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

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

    Another choice is use the ddply function from the ggplot2 library. But you mention you mostly want to do a plot of peak vs. year, so you could also just use qplot:

    A <- read.table("example.txt",header=TRUE)
    library(ggplot2)
    qplot(peak,year,data=A,colour=site,geom="line",group=site)
    ggsave("peak-year-comparison.png")
    

    On the other hand, I do like David Smith's solution that allows the applying of the function to be run across several processors.

提交回复
热议问题