data.frame - How to split/subset a dataframe into multiple dataframes in R -



data.frame - How to split/subset a dataframe into multiple dataframes in R -

i have looked through web , stackflow , not able find solution problem. don't know of dplyr or loop more efficient.

below illustration of dataframe (my own datasets have more 10,000 rows) split in 3 based on column b (<250) list 3 objects or 3 individual dataframes. each new dataframe, like, example, count number of points (or length of dataframe) , duration (column time in seconds). suggestion appreciated.

thank you

martin

dput(mydata) structure(list(time = c(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 0l, 11l, 12l, 13l, 14l, 15l, 16l, 17l, 18l), = c(4l, 5l, 6l, 7l, 3l, 7l, 8l, 10l, 11l, 8l, 10l, 12l, 14l, 6l, 14l, 16l, 20l, 22l ), b = c(100.25, 150.75, 200, 1000.56, 2000.1, 100, 150, 50, 25.2, 102.25, 152.75, 202, 1002.56, 2002.1, 102, 152, 52, 27.2 )), .names = c("time", "a", "b"), class = "data.frame", row.names = c(na, -18l))

grab iranges bioconductor:

runs <- slice(rle(df$b), upper=250)

this rleviews object, view (range) every run under 250. can extract width of views (the number of points in each info frame):

width(runs)

you can split info frame list this:

blocks <- extractlist(df, ranges(runs))

note blocks formal splitdataframelist.

to compute duration, can extract time column integerlist , compute difference between lastly , first element of every list element:

time <- blocks[,"time"] ptail(time, 1) - phead(time, 1)

this happens without forming separate list elements (the list lazily managed) , should fast.

r data.frame extract subset

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -