简体   繁体   中英

Split R data frame into smaller data frames based on string

I want to split this data frame: https://ibb.co/gJ2Xdfd into smaller data frames based on their rows. The top table is an aggregation of the totals of the subsequent tables so I don't need to read this data (as it's already contained in the other tables).

I've searched the df for occurrences of Height (m) that give me the rows to use as start and end points for splitting but I can't figure out how to use this vector iteratively

occur <- which(df['1'] == "Height (m)") gives me [1] 2 17 33 49 but how do I use the different elements as start and end points iteratively in code like df <- df[(occur[1]+1):(occur[2]-1), ]

It looks like you want all the rows where there is a number in the first column, apart from the first five rows that contain a number in the first column. Here's how you say that in R:

df[grep("[[:digit:]]", df['1'])[-(1:5)],]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM