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

后端 未结 7 1177
北荒
北荒 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 17:57

    I seem to recall that plain old split() has a method for data.frames, so that split(data,data$site) would produce a list of blocks. You could then operate on this list using sapply/lapply/for.

    split() is also nice because of unsplit(), which will create a vector the same length as the original data and in the correct order.

提交回复
热议问题