[R] replicate lines of data frame

Henri-Paul Indiogine hindiogine at gmail.com
Thu Aug 25 23:15:10 CEST 2011


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



More information about the R-help mailing list