创建数据框:
ID = c("A", "B", "C", "A", "B", "C", "A", "B", "C")
Date = c("01/01/2022", "01/02/2022", "01/03/2022", "01/01/2022", "01/02/2022", "01/03/2022", "01/01/2022", "01/02/2022", "01/03/2022")
Value = c("45", "24", "33", "65", "24", "87", "51", "32", "72")
df <- data.frame(ID,Date,Value)
拆分数据:
df_a <- df %>%
filter(ID =="A")
df_b <- df %>%
filter(ID =="B")
df_c <- df %>%
filter(ID =="C")
打印数据:
现在只需运行下面的拆分数据帧:
df_a
df_b
df_c
这将为您提供以下输出:
ID Date Value
1 A 01/01/2022 45
2 A 01/01/2022 65
3 A 01/01/2022 51
ID Date Value
1 B 01/02/2022 24
2 B 01/02/2022 24
3 B 01/02/2022 32
ID Date Value
1 C 01/03/2022 33
2 C 01/03/2022 87
3 C 01/03/2022 72