[R] Repeating lines in a data frame

Martin Henry H. Stevens HStevens at MUOhio.edu
Tue Oct 18 21:51:47 CEST 2005


See ?order, e.g.,
(a <- expand.grid(1998:2000,1:2,1:3))
attach(a)
(b <- a[order(Var1,Var3,Var2),])

Hank


On Oct 18, 2005, at 3:20 PM, Guenther, Cameron wrote:

> Hello,
> I have a much larger dataset that is similar in form to:
>  year species length count
>  1998       1    150     1
>  1998       2    200     1
>  1998       3    250     2
>  1999       1    150     3
>  1999       2    200     4
>  1999       3    250     5
>  2000       1    150     1
>  2000       2    200     1
>  2000       3    250     1
>  2001       1    150     2
>  2001       2    200     3
>  2001       3    250     1
>  2002       1    150     1
>  2002       2    200     2
>  2002       3    250     3
>
> What I want is to have a line of data for each year x species x length
> group combination
> I would like the ouput to be:
>
> Year species length count
> 1998       1    150     1
> 1998       2    200     1
> 1998       3    250     1
> 1998       3    250     1
> 1999       1    150     1
> 1999       1    150     1
> 1999       1    150     1
> 1999       2    200     1
> .
> .
> .
>
> Can anyone help me with a for statement of a function that can
> accomplish this?
> Thanks
>
> Cameron Guenther
> Associate Research Scientist
> FWC/FWRI, Marine Fisheries Research
> 100 8th Avenue S.E.
> St. Petersburg, FL 33701
> (727)896-8626 Ext. 4305
> cameron.guenther at myfwc.com
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting- 
> guide.html
>

Dr. Martin Henry H. Stevens, Assistant Professor
338 Pearson Hall
Botany Department
Miami University
Oxford, OH 45056

Office: (513) 529-4206
Lab: (513) 529-4262
FAX: (513) 529-4243
http://www.cas.muohio.edu/~stevenmh/
http://www.muohio.edu/ecology/
http://www.muohio.edu/botany/
"E Pluribus Unum"




More information about the R-help mailing list