我尝试做的是根据较大数据帧中第一列的值将较大的数据帧过滤成78个唯一的数据帧。我能想到的唯一正确的方法是在for()循环中应用filter()函数:
for (i in 1:nrow(plantline))
{x1 = filter(rawdta.df, Plant_Line == plantline$Plant_Line[i])}问题是我不知道如何创建一个新的数据框,比如x2、x3、x4……每次循环运行的时候。
有没有人能告诉我这是否可能,或者我是否应该尝试用其他方式来做这件事?
发布于 2018-07-25 22:57:48
这个问题肯定有很多重复的地方
split(plantline, plantline$Plant_Line)将创建一个data.frames列表。
但是,根据您的用例,可能没有必要将大型data.frame拆分为多个部分,因为可以使用分组。
发布于 2018-07-25 23:01:33
你可以使用split -
# creates a list of dataframes into 78 unique data frames based on
# the value of the first column in the larger data frame
lst = split(large_data_frame, large_data_frame$first_column)
# takes the dataframes out of the list into the global environment
# although it is not suggested since it is difficult to work with 78
# dataframes
list2env(lst, envir = .GlobalEnv)数据帧的名称将与第一列中变量的值相同。
发布于 2018-07-25 22:53:47
如果我们能看到数据帧,那就更容易了……
尽管如此,我还是提出了一些建议。您可以创建数据帧列表:
dataframes <- vector("list", nrow(plantline))
for (i in 1:nrow(plantline)){
dataframes[[i]] = filter(rawdta.df, Plant_Line == plantline$Plant_Line[i])
}https://stackoverflow.com/questions/51521812
复制相似问题