Hi:

df <- read.table(textConnection("
+   xloc  yloc  yield
+ 1  10    12    95
+ 2  11    10    81
+ 3  12    11    20
+ 4  12    11    10"), header = TRUE)

with(df, xtabs(yield ~ yloc + xloc))
    xloc
yloc 10 11 12
  10  0 81  0
  11  0  0 30
  12 95  0  0

HTH,
Dennis

On Tue, Feb 22, 2011 at 11:30 PM, Nicolas Gutierrez <nicol...@uw.edu> wrote:

> Hi all (again),
>
> I have a data frame "pop":
>
>   xloc  yloc  yield
> 1  10    12    95
> 2  11    10    81
> 3  12    11    20
> 4  12    11    10
>
> And I want to get the sum of yield for the cell (pop$xloc, pop$yloc) in a
> matrix as follows:
>
>            xloc
>          10  11  12
>       10 0   81  0
>  yloc  11 0   0   30
>       12 95  0   0
>
>
> Any ideas? thanks!
>
> Nico
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to