I'm trying to drop columns that have more than 90% of NA values present, I've followed the following but I only get a values in return, not sure what I can be doing wrong. I would be expecting an actual data frame, I tried putting as.data.frame in front but this is also erroneous.
Linked Post: Delete columns/rows with more than x% missing
Example DF
gene cell1 cell2 cell3 A 0.4 0.1 NA B NA NA 0.1 C 0.4 NA 0.5 D NA NA 0.5 E 0.5 NA 0.6 F 0.6 NA NA Desired DF
gene cell1 cell3 A 0.4 NA B NA 0.1 C 0.4 0.5 D NA 0.5 E 0.5 0.6 F 0.6 NA Code
#Select Genes that have NA values for 90% of a given cell line df_col <- df[,2:ncol(df)] df_col <-df_col[, which(colMeans(!is.na(df_col)) > 0.9)] df <- cbind(df[,1], df_col)