[R] replicate lines of data frame

Henri-Paul Indiogine hindiogine at gmail.com
Thu Aug 25 21:22:18 CEST 2011


Greetings!

I am just now learning to use R for my dissertation project.   I need
to manipulate a lot of text and numeric data.  I created a data frame
that has 7 columns and 127 unique rows.  Now I need to replicate each
line 6 times and then later change values in the first 2 columns.

I am trying to figure out how to accomplish this.  I think that I need
to use rep(my.df, each=6) but it does not quite work.

This is the sample data frame

"col1" "col2" "col3" "col4" "col5" "col6" "col7"
foo      bar    1        blah   blah   blah   blah
foo      bar    2        blah   blah   blah   blah
foo      bar    3        blah   blah   blah   blah
......
......


I need to change it into this:

"col1" "col2" "col3" "col4" "col5" "col6" "col7"
foo      bar    1        blah   blah   blah   blah
foo      bar    1        blah   blah   blah   blah
....
foo      bar    1        blah   blah   blah   blah
foo      bar    2        blah   blah   blah   blah
foo      bar    2        blah   blah   blah   blah
....
foo      bar    2        blah   blah   blah   blah
foo      bar    3        blah   blah   blah   blah
foo      bar    3        blah   blah   blah   blah
....
foo      bar    3        blah   blah   blah   blah
.....
.....
and so on.

Thanks!

Henri-Paul



-- 
Henri-Paul Indiogine

Curriculum & Instruction
Texas A&M University
TutorFind Learning Centre

Email: hindiogine at gmail.com
Skype: hindiogine
Website: http://people.cehd.tamu.edu/~sindiogine



More information about the R-help mailing list