2

I know the split command is the easiest way to turn a df into a list of df objects, but how can they be assigned to different (seperated) dataframes?

df.List <- split(df, df$column)
4

2 回答 2

5

看功能list2env。尝试:

list2env(split(df, df$column), envir = .GlobalEnv)
于 2013-09-13T08:06:22.213 回答
1

特此我的解决方案(以 iris 数据集为例)

两种方式:

list_df <- split(iris, iris$Species) #split the dataset into a list of datasets based on the value of iris$Species
list2env(list_DF, envir= .GlobalEnv) #split the list into separate datasets

单程:

list2env(split(iris, iris$Species), envir = .GlobalEnv)

for或者您可以使用循环为新数据集分配自定义名称:

iris_split <- split(iris, iris$Species)
new_names <- c("one", "two", "three")
for (i in 1:length(iris_split)) {
  assign(new_names[i], iris_split[[i]])
于 2013-11-13T14:30:46.850 回答