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
Post a Comment