r - Variable in colnames -


i want combine text , variable in colnames. example i've tried (mix between python , r):

list_names <- "henk", "ash", "brock", "piet" list_age <- 14 , 12, 44, 56  (i in range 1:4) {   colnames (df) <-  c("this name", list_names[[i]], "and i'am", list_age[[i]], "years old." } 

i tried this, error colnames has got many arguments.

does know how put these variables in colnames?

kr, arnand

we may need paste (using r)

colnames(df) <- paste("this name", list_names, "and i'am", list_age) colnames(df) #[1] "this name henk , i'am 14"  "this name ash , i'am 12"   "this name brock , i'am 44" #[4] "this name piet , i'am 56"  

data

list_names <- c("henk", "ash", "brock", "piet") list_age <- c(14 , 12, 44, 56) df <- data.frame(v1 = 1:4, v2 = 2:5, v3 = 3:6, v4 = 4:7) 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -