r - Selecting multiple odd or even columns/rows for dataframe -


is there way in r select many non-consecutive i.e. odd or rows/columns?

i'm plotting loadings principal components analysis. have 84 rows of data ordered this: x_1 y_1 x_2..... x_42 y_42

and @ moment creating dataframes x , y loadings figures this:

data.pc = princomp(as.matrix(data))  x.loadings <- data.frame(x=data.pc$loadings[c(1, 3, 5, 7, 9, 11, 13 ,15, 17, 19,  21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41), 1])  yloadings <- data.frame(y=data.pc$loadings[c(2, 4, 6, 8, 10, 12, 14, 16, 18, 20,  22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42), 1]) 

surely there's easier way this?

you can generate sequences seq:

even_indexes<-seq(2,42,2) odd_indexes<-seq(1,41,2) 

then,

  x.loadings <- data.frame(x=data.pc$loadings[odd_indexes,1]) 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -