Let's say I have the following data frame:
a <- runif(10)
dd <- as.data.frame(t(a))
names(dd) <- c("ID", "a", "a2", "b", "b2", "f", "XXX", "1", "4", "8")
In dplyr
, there is a nice way to select a number of columns. For example, to select the columns between column a and column f, I can use
dd %>% dplyr::select(a:f)
In my problem, the columns of the last part of the data frame may vary, yet they always have as name a number between 1 and 99. However, I can not seem to be able to do the same trick as above:
> dd %>% select(1:99)
Error: Position must be between 0 and n
> dd %>% select("1":"99")
Error: Position must be between 0 and n
Which is because using select()
tries to select columns by position in this way.
I would like to be able to obtain a data frame with all columns between a and f, and those with labels that are numbers between 1 and 99. Is that possible to do in one go with select()
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…