将数据帧拆分为 R 中重叠列的新数据帧
我有一个包含数百列和尽可能多行的数据框。第一列包含 ID。以下所有列均代表观察结果。它们的值为 1 或 0。现在我想将数据帧划分为仅包含重叠列的新数据帧。我从哪里开始呢?抱歉,我不知道......
df_input <- structure(list(
a <- c("A", "B", "C", "D", "E", "F"),
b <- c(0, 0, 0, 1, 1, 1),
c <- c(0, 1, 1, 0, 0, 0),
d <- c(1, 0, 0, 0, 0, 0),
e <- c(1, 1, 0, 0, 0, 0),
f <- c(1, 0, 0, 0, 0, 0)
), class = "data.frame", row.names = c(NA, -6L), .Names = c("id", "b", "c", "d", "e", "f"))
在我的示例中,需要创建两个数据框。 A 列的一个数据框,因为它与其他列没有重叠。所有其他列的第二个数据帧,因为它们在不同的行中彼此没有重叠。
I have a dataframe with many hundreds of columns and as many rows. The first column contains an ID. All following columns represent an observation. These have the values 1 or 0. Now I want to divide the dataframe into new dataframes that contain only those columns that are overlapping. Where do I start here? Sorry, I have no idea...
df_input <- structure(list(
a <- c("A", "B", "C", "D", "E", "F"),
b <- c(0, 0, 0, 1, 1, 1),
c <- c(0, 1, 1, 0, 0, 0),
d <- c(1, 0, 0, 0, 0, 0),
e <- c(1, 1, 0, 0, 0, 0),
f <- c(1, 0, 0, 0, 0, 0)
), class = "data.frame", row.names = c(NA, -6L), .Names = c("id", "b", "c", "d", "e", "f"))
In my example, two dataframes would need to be created. One dataframe for column A, because it has no overlap with other columns. A second dataframe for all other columns, since they have no overlapps with each other in different rows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论