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

后端 未结 7 1198
北荒
北荒 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:55

    Here's what I would do, although it looks like you guys have it handled by library functions.

    for(i in 1:length(unique(data$site))){
      constrainedData = data[data$site==data$site[i]];
      doSomething(constrainedData);
    }
    

    This kind of code is more direct and might be less efficient, but I prefer to be able to read what it is doing than learn some new library function for the same thing. makes this feel more flexible too, but in all honesty this is just the way I figured it out as a novice.

提交回复
热议问题