r - Subset data frame by multiple sets of indicies -


if have data frame this:

    x <- data.frame(col1 = rep(2,10),col2 = rep(3,10)        ,col3 = rep(2,10),col4 = rep(3,10),col5 = rep(2,10)        ,col6 = rep(3,10),col7 = rep(2,10),col8 = rep(3,10))      col1 col2 col3 col4 col5 col6 col7 col8 1     2    3    2    3    2    3    2    3 2     2    3    2    3    2    3    2    3 3     2    3    2    3    2    3    2    3 4     2    3    2    3    2    3    2    3 5     2    3    2    3    2    3    2    3 6     2    3    2    3    2    3    2    3 

and want column names col 1-4 , 6-8. in other words this:

colnames(x[1:4,6:8]) 

how can that?

this it:

colnames(x)[c(1:4,6:8)] #[1] "col1" "col2" "col3" "col4" "col6" "col7" "col8" 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -