How to split a data frame by rows, and then process the blocks?

后端 未结 7 1175
北荒
北荒 2020-12-08 17:32

I have a data frame with several columns, one of which is a factor called \"site\". How can I split the data frame into blocks of rows each with a unique value of \"site\",

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 18:11

    You could use the split function If you opened your data as:

    data <- read.table('your_data.txt', header=T)
    blocks <- split(data, data$site)
    

    After that, blocks contains data from each block, that you can access as other data.frame:

    plot(blocks$ALBEN$year, blocks$ALBEN$peak)
    

    And so on for each plot.

提交回复
热议问题