So I'm new to R and I am trying to make the columns of this dataset more readable:
with the rename() function from dplyr:
x <- names(data)
cols <- gsub('\\.', ' ', x)
for (col in ncol(data)) {
data <- data %>% rename(cols[col] = names(data)[col])
col
}
but I get an error, which I can't fix with my knowledge or google:
Error in source("~/Desktop/r/assignment1/best.R") :
~/Desktop/r/assignment1/best.R:9:45: unexpected '='
8: for (col in ncol(data)) {
9: outcome <- data %>% rename(cols[col] =
I would be very grateful if someone could tell me where to look for the solution to this.
Thanks a lot!
names(data) <- gsub('\\.', ' ', names(data))- Ronak Shahnames(data) <- gsub(...)No loop needed or anything - Sotosvec[ind] <- 1, that does not work indplyrfunctions, sorename(cols[col] = ...)ormutate(cols[col] = ...)or similar will not work. There are workarounds (perhapsif_elsein some cases), but I believe that thegsubworkaround here is more succinct. - r2evans