vendredi 22 juin 2018

Change the value of variables that occur 80% of the times in each row, R

In my data, I have 74 observations (rows) and 128 variables (columns), where each variable takes either 0 or 1 as value. In R, I am trying to write a code, where I can find in each row, the variables that has 1 as value and calculate 80% of the times 1 appears in each row. Pick those variables that has 80% of the times value as 1 and change the value from 1 to 0. I could write code, where I can calculate the 80% of times, 1 appears in each row, but I am not able to pick these variables in each row and change their value from 1 to 0.

data# data frame with 74 observations and 128 variables

row1 <- data[1,]

count1 <- length(which(data[1,] == 1)) # #number of 1 in row 1

print(count1)

perform <- 80/100*count1# 80% of count1

Any suggestions

Thank you

Priya




Aucun commentaire:

Enregistrer un commentaire