【发布时间】:2021-12-06 22:26:16
【问题描述】:
我想知道如何在下面拆分我的data,以便我得到一个较小的dataf.rames 列表,其中每个都包含一对独特的type?
我的desired_output 如下所示。
请注意,这只是一个玩具数据,因此type 可以是任何其他变量。另外,请注意,如果特定的 type 只有一行(如 type == 4),我想通过警告排除它:
type 4 has just one row thus is excluded.
m=
"
obs type
1 1
2 1
3 a
4 a
5 3
6 3
7 4
"
data <- read.table(text = m, h=T)
desired_output <-list(
data.frame(obs=1:4, type=c(1,1,"a","a")),
data.frame(obs=c(1,2,5,6), type=c(1,1,3,3)),
data.frame(obs=3:6, type=c("a","a",3,3))
)
# warning: type 4 has just one row thus is excluded.
【问题讨论】:
标签: r dataframe function dplyr tidyverse