Reputation: 49
I have a data frame with 200 columns, I want to extract column 5, 10, 15, 20...195, 200 for a new df. But I don't want to type all of them. Is there any method to make it easier?
df1 <- df[,c(5,10,15,20,25,30,35,40,45,...,200)]
Upvotes: 1
Views: 18
Reputation: 887213
We can use seq
to create the index
df1 <- df[, seq(5, 200, by = 5)]
Upvotes: 1