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

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 08 Jul 2006 - 20:42:46 EST

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@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



R-help@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 Received on Sat Jul 08 20:48:49 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 09 Jul 2006 - 00:15:59 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.