Printing Specific Rows in R -



Printing Specific Rows in R -

hi guys working big info frame records employee time card info specific months. want print out entire row of employees record maximum of 3 zeros in 3 different months. believe need utilize apply function: apply(employee, 1, ...) employee name of info frame, 1 allows iterate on each row, unsure how select have 3 or fewer zeros in row. appreciate help!

you utilize rowsums(). here's illustration false data.

> d <- data.frame(x1 = c(0, 1, 0, 0), x2 = c(0, 2, 2, 0), x3 = c(0, 2, 0, 0), x4 = c(3, 0, 0, 0)) > d # x1 x2 x3 x4 # 1 0 0 0 3 # 2 1 2 2 0 # 3 0 2 0 0 # 4 0 0 0 0

the can subset rows logical value of x == 0 sums 3 or less:

> d[rowsums(d == 0, na.rm = true) <= 3, ] # x1 x2 x3 x4 # 1 0 0 0 3 # 2 1 2 2 0 # 3 0 2 0 0

r

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -