P
P
paroletatel2021-05-11 14:34:39
R
paroletatel, 2021-05-11 14:34:39

How to add a row in R to data.frame, which will contain information about the number of certain values ​​in the corresponding column?

I have a dataframe in which some columns consist entirely or partly of [Not Available]. I need to delete columns in which their share is more than 90%. As I understand it, this must be done through a loop. But how can I add the corresponding row, and add the number of [Not Available] values ​​in the columns to it? And then delete certain columns.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
paroletatel, 2021-05-11
@paroletatel

names <- names(data_pheno_DF)

df <- data.frame(first = c(1))

for(i in 1:(length(names)-1)){
  c <- c(1)
  df <- cbind(df, c)
}
names(df) <- names

data_pheno_DF <- rbind(df, data_pheno_DF)

#data_ph <- data_pheno_DF
data_pheno_DF <- data_ph

for(i in 1:(length(names))){
v <- data_pheno_DF
data_pheno_DF[1] <- (length(v[v == "[Not Available]"]) + length(v[v == "[Not Applicable]"]))/length(v)
}

for(i in length(names):1){
  if(data_pheno_DF[1] > 0.85){data_pheno_DF[i] <- NULL}
}

data_pheno_DF <- data_pheno_DF[-c(1), ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question