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
Hi Henri-Paul, Try ("x" is your data): x[rep(1:nrow(x), each = 6),] HTH, Jorge On Thu, Aug 25, 2011 at 3:22 PM, Henri-Paul Indiogine <> wrote:> 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@gmail.com > Skype: hindiogine > Website: http://people.cehd.tamu.edu/~sindiogine > > ______________________________________________ > 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]]
Hi Jorge! 2011/8/25 Jorge I Velez <jorgeivanvelez at gmail.com>:> Try ("x" is your data): > x[rep(1:nrow(x), each = 6),]Yes, it works. Thanks! I see that the row names are now: 1, 1.1, 1.2, 1.3, 1.4, 1.5, 2, 2.1 ..... It does not bother me, but is this going to be a problem later on? I need to further manipulate the first 2 columns. This is what I would like to do: (1) the first column should have: "doc_date", "doc_type", "doc_id", "title", "author", "author_cat" repeated down the data frame. You can see that there are 6 strings, one for each of the 6 replicated rows. (2) Then I need to replace in the second column all values except the one on the 3rd replication. Thanks a bunch! This is my dissertation work, so very, very important for me :-) Best, 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