I have a very large dataframe with missing values. For some groups there are few columns, where all values are missing.
analysis <- data.frame(Col = names(dd), stringsAsFactors = FALSE)
c <- c()
for (i in 1:3) {
df_group <- subset(dd, dd$group == i)
for (col in colnames(df_group)) {
indx <- tail(names(sort(table(df_group[, col]))), 1)
indx <- ifelse(length(indx) == 0, NA, indx)
c <- append(c, indx)
}
analysis <- cbind(analysis, c)
}
This code without the ifelse
gave me c
, which was too short (missing values for columns which contains only NAs). With the ifelse
I am getting too long c
. Is there any other way to change the ifelse
?