1 year ago

#361594

test-img

Olaf Pleines

Split a dataframe into new dataframes of overlapping columns in R

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.

r

dataframe

split

intersection

0 Answers

Your Answer

Accepted video resources