[R] can rows of text be repeated using R to create a new datafile

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jul 8 12:42:46 CEST 2006


Open Excel, select the data and press ctrl-C.
In R, type this line at the console to
read the clipboard into a data frame DF (or
see the section on Excel in the R Import/Export
manual for other ways):

  DF <- read.delim("clipboard", header = TRUE)

Now you can do this:

   DF[rep(1:nrow(DF), each = 4),]

On 7/8/06, Bob Green <bgreen at dyson.brisnet.org.au> wrote:
> I am hoping for some advice as to whether the following task can be
> performed in R?
>
> I have a spreadsheet with 325 rows x 3 columns. The data was collected from
> 40 individuals who in most instances generated 8 bi-polar constructs  (the
> poles are separated by //). The first column is the construct number =
> 1  to 325. The second is an id number =1 to 40; the third column is the
> data to be coded.  Because persons 1, 18 & 40 generated 9 rows of data, and
> person 5, 10 rows; rows =325 not 320.
>
> What I want to do is repeat each row a set number of times - hopefully 4
> (the number of coders to code the data). Once repeated there would be 4
> conids x 1 , 4  x 2 etc …. 4x 325.
>
>
> Currently this is how the first 2 rows look:
>
> conid   person  construct
> 1       1       offence against property  // offence against person
> 2       1       insight & cooperative with treatment //  lack insight
>
> This is how I want them to look after editing.
>
> conid   person  construct
> 1       1       offence against property  // offence against person
> 1       1       offence against property  // offence against person
> 1       1       offence against property  // offence against person
> 1       1       offence against property  // offence against person
> 2       1       insight & cooperative with treatment //  lack insight
> 2       1       insight & cooperative with treatment //  lack insight
> 2       1       insight & cooperative with treatment //  lack insight
> 2       1       insight & cooperative with treatment //  lack insight
> 2       1       insight & cooperative with treatment //  lack insight
>
>
>
> Any assistance is much appreciated,
>
> Bob



More information about the R-help mailing list