I want to select several data in a data frame, each N column. I will explain my problem with a copy presenter example:
set.seed (100) data & lt; - data.frame (repeat (18, sample (0: 100,18, delegate = TRUE)))
From the data, I data [1: 6, 1] , then
data [7:12, 7]
, then data [13:19, 13]
, and so forth. Obviously, I'm working with a large dataset (> 10000 rows and columns), which is why I like an automated way to do this.
I have already tried to define a sequence ( seq ()
) but it could not be understood how it can be implemented on this problem. Thanks for the help!
matrix
indexing can be successful here:
sel & lt; # Line call # [, 1] [, 2] # [1,] 1 1 # - # cbind (sequence (niro (data)), representative (seq (1, ncol (data), 6), each = 6) ... # [6,] 6 # # [7,] 7 7 # ... # [12,] 12 7 # [13,] 13 13 # ...
Then:
data [sel] # [1] 31 26 55 5 47 48 97 3 92 73 20 84 37 30 55 37 85 62
No comments:
Post a Comment