Re: [R] Adding NAs to data.frame

2010-05-08 Thread Gabor Grothendieck
That seems to be a suitable situation for a loop although you might wish to write it like this: for ( nm in names(df) ) df[ v[[nm]], nm ] <- NA Note that R does not require semicolons at the end of each statement. On Sat, May 8, 2010 at 11:12 AM, wrote: > Hello, after the creation of a data.f

Re: [R] Adding NAs to data.frame

2010-05-08 Thread Henrique Dallazuanna
Try this: df <- as.data.frame(mapply(`[<-`, x = df, i = v, NA)) On Sat, May 8, 2010 at 12:12 PM, wrote: > Hello, after the creation of a data.frame I like to add NAs as follows: > > n <- 743; > x <- runif(n, 1, 7); > Y <- runif(n, 1, 7); > Ag6 <- runif(n, 1, 7); > df <- data.frame(x, Y, Ag6);