How do I append data frames one after the other to form another data frame? Whether a data frame would be included or not will be decided by a criteria.
以下是一个例子数据:
d1 <- data.frame(MyGroups =sample(LETTERS,100,replace=TRUE),
MyInt = sample(c(1:20),100,replace=TRUE))
现在,我该如何从 My Groups 中选择有超过10个变数 MyInt 平均值的组( A, B, C...)?
我尝试了以下的尝试,但没有成功。在这里,我正在根据给定的标准将数据框架附加到一个文件中。
require("plyr")
keepGrp <- function(df0) {
if(max(df0$MyInt < 10)) {df0 <- NULL}
write.csv(df0, mytable.txt ,append=TRUE,sep= , )
}
ddply(d1,.(MyInt),function(x) keepGrp(x))
The desired data frame should be in file mytable.txt I am fully sure there is a better way to do what I am trying to do. I would be happy to clarify my question if I need to do so. I will appreciate of someone can (1) show me a feedback on improving my programming thoughts (2) give me a solution to my problem.