Like this?
> V <- c("fee","fie","foe")
> aq <- head(airquality) # Just to get a shorter example
> aq[V] <- 0
> aq
Ozone Solar.R Wind Temp Month Day fee fie foe
141 190 7.4 67 5 1 0 0 0
236 118 8.0 72 5 2 0 0 0
312 149 12.6 74 5 3 0
Another option is
d0[paste0("V", 1:nrow(d1))] <- 0
--Ista
On Sun, Apr 22, 2018 at 4:23 AM, Eric Berger wrote:
> Hi Luca,
> How about this?
>
> # create some dummy data since I don't have your d0 or d1
>> n <- 3
>> d0 <- data.frame(a=runif(5),b=runif(5))
>
> # here's the suggested code
>> d1 <-
Hi Luca,
How about this?
# create some dummy data since I don't have your d0 or d1
> n <- 3
> d0 <- data.frame(a=runif(5),b=runif(5))
# here's the suggested code
> d1 <- cbind(d0, matrix(0,nrow(d0),n))
> colnames(d1)[1:n + ncol(d0)] <- paste("V",1:n,sep="")
HTH,
Eric
On Sun, Apr 22, 2018 at 1
Hi,
I am a bit rusty with R programming and do not seem to find a solution to
add a number of variables to my existing dataframe. Basically I need to add
n=dim(d1)[1] variables to my d0 dataframe and I would like them to be named
V1, V2, V3, ... , V[dim(d1)[1])
When running the following code:
f
4 matches
Mail list logo