0

In a data frame where all colums contain either missing or the same data, how can I get a vector with all the data and nothing missing, assuming no colum has all the values.

Example data frame here as I'm struggling to describe what I mean

x <-data.frame(c( "r", "t", "", "y"), c("", "t", "x", "y"), c("r","","x", ""))

desired output would be a vector like the one given with c("r", "t", "x", "y"), or a column like that.

I have tried using duplicated and distinct but haven't managed to work it.

d.b
  • 32,245
  • 6
  • 36
  • 77
mmm
  • 23
  • 3

2 Answers2

2
temp = unique(c(t(x)))
temp = temp[temp != ""]
temp
#[1] "r" "t" "x" "y"
d.b
  • 32,245
  • 6
  • 36
  • 77
0

My solution is a bit more convoluted, but here it goes.

apply(x, 1, function(y) names(table(y)[max(table(y))]))
[1] "r" "t" "x" "y"
Rui Barradas
  • 70,273
  • 8
  • 34
  • 66