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

后端 未结 7 1197
北荒
北荒 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:21

    There are two handy built in functions for dealing with these kind of situations. ?aggregate and ?by. In this case because you want a plot and aren't returning a scalar, use by()

    data <- read.table("example.txt",header=TRUE)

    by(data[, c('year', 'peak')], data$site, plot)

    The output says NULL because that's what plot returns. You might want to set the graphics device to pdf to capture all the output.

提交回复
热议问题