Hi
I would like to know how to pivot a table that will sum the number of plants
(a or b) for each location (x,y,z)
I have read on the listserve similar questions but which involve summing up
numbers rather than factors. I have also read about the R package reshape
on the listserve but wanted to know if there's a way to do it easily without
the package
Thanks for the help!
location plant
x a
x b
x b
y b
y b
y a
z a
z a
into a table like this
x y z
a 1 1 2
b 2 2 0
[[alternative HTML version deleted]]
Is this what you want:> xlocation plant 1 x a 2 x b 3 x b 4 y b 5 y b 6 y a 7 z a 8 z a> table(x$plant,x$location)x y z a 1 1 2 b 2 2 0>On Wed, May 7, 2008 at 2:56 PM, juanita choo <juanitachoo at gmail.com> wrote:> Hi > I would like to know how to pivot a table that will sum the number of plants > (a or b) for each location (x,y,z) > I have read on the listserve similar questions but which involve summing up > numbers rather than factors. I have also read about the R package reshape > on the listserve but wanted to know if there's a way to do it easily without > the package > Thanks for the help! > > location plant > x a > x b > x b > y b > y b > y a > z a > z a > > into a table like this > > > x y z > a 1 1 2 > b 2 2 0 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
assuming what you have is a dataframe called x
try:
table(Plant=x$plant,Location=x$location)
Location
Plant x y z
a 1 1 2
b 2 2 0
or simply:
table(x$plant,x$location)
x y z
a 1 1 2
b 2 2 0
thanks
juanita choo wrote:>
> Hi
> I would like to know how to pivot a table that will sum the number of
> plants
> (a or b) for each location (x,y,z)
> I have read on the listserve similar questions but which involve summing
> up
> numbers rather than factors. I have also read about the R package reshape
> on the listserve but wanted to know if there's a way to do it easily
> without
> the package
> Thanks for the help!
>
> location plant
> x a
> x b
> x b
> y b
> y b
> y a
> z a
> z a
>
> into a table like this
>
>
> x y z
> a 1 1 2
> b 2 2 0
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
>
-----
Yasir H. Kaheil, Ph.D.
Catchment Research Facility
The University of Western Ontario
--
View this message in context:
http://www.nabble.com/pivoting---summing-up-factors-tp17112158p17112407.html
Sent from the R help mailing list archive at Nabble.com.