Re: [R] Inserting a blank row to every other row

2016-04-25 Thread David L Carlson
ailing List Subject: Re: [R] Inserting a blank row to every other row Oh, sorry, I just realized that I messed up the indicing. Here is the correct way: > z <- data.frame(a=1:3,b = letters[1:3]) > i <- seq_len(nrow(z)) > z<-z[rep(i,e=2),] > z[2*i, ] <- matrix(NA, nr=nrow(z

Re: [R] Inserting a blank row to every other row

2016-04-24 Thread Giorgio Garziano
Starting from this data frame: my.df <- data.frame(num = 1:5, let = letters[1:5]) > my.df num let 1 1 a 2 2 b 3 3 c 4 4 d 5 5 e > and inserting a blank row (NAs row) for each one of my.df rows. na.df <- data.frame(num = NA, let = NA) my.df <- do.call(rbind, apply(my.df,

Re: [R] Inserting a blank row to every other row

2016-04-24 Thread Bert Gunter
Oh, sorry, I just realized that I messed up the indicing. Here is the correct way: > z <- data.frame(a=1:3,b = letters[1:3]) > i <- seq_len(nrow(z)) > z<-z[rep(i,e=2),] > z[2*i, ] <- matrix(NA, nr=nrow(z),nc=ncol(z)) > z Still doubt that this is a good idea, though. -- Bert Bert Gunter

Re: [R] Inserting a blank row to every other row

2016-04-24 Thread Bert Gunter
Well, something like this would work (there may be slicker solutions): > z <- data.frame(a=1:3,b = letters[1:3]) > i <- seq_len(nrow(z)) *2 > z <-rbind(z,z) > z[i, ] <- matrix(NA, nr=nrow(z),nc=ncol(z)) > z ab 1 1a 2 NA 3 3c 4 NA 5 2b 6 NA But I agree with you that there

Re: [R] Inserting a blank row to every other row

2016-04-24 Thread Ulrik Stervbo
Hi Saba, I don't know how to do what you want and I also cannot see why. If you describe what you hope to achieve there might be a different solution. Best wishes Ulrik Saba Sehrish via R-help schrieb am So., 24. Apr. 2016 14:04: > Hi > > I need to insert a blank row

[R] Inserting a blank row to every other row

2016-04-24 Thread Saba Sehrish via R-help
Hi I need to insert a blank row after every row in R data frame. I have achieved it through: df[rep(1:nrow(df),1,each=2),] But it inserts a row with name of previous row, while i want a complete blank row without any name/title. Please guide me Regards Saba