I want to just run a small data let say data<-read.csv("test.csv", header=TRUE)
with column name 100, 102, ..., 300
(Note: in data.frame, R would add X
in front of the column name since it is a number. How I can choose the data frame from spesific column name with sequence 4? Which is
X100 X104 X108 X112 ...
1.2 1.3 1.1 1.5
1.2 1.3 1.1 1.5
I tried here but not working
new<-data[,c(paste0("'X",seq(100,300,4),"'",collapse=",")))
I think you have a little too much in your paste
function. Try this instead:
new <- data[, paste0("X", seq(100,300,4))]
That should work based on the info you provided
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.