将数据帧拆分为 R 中重叠列的新数据帧

发布于 2025-01-18 05:20:48 字数 528 浏览 0 评论 0原文

我有一个包含数百列和尽可能多行的数据框。第一列包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文