I am trying to calculate count on non zero elements in row in dat frame but not working.
condition: just want to exclude one column while calculating count of non zero elements in row
i just want to select T_1_1,T_1_2,T_1_3.....and exclude T_1_0 and create a new column and check how many non zero elements available in row. what i am doing wrog here ..??
df <- data.frame("T_1_1"= c(68,24,0,105,58,0,135,126,24),
"T_1_2"=c(26,105,0,73,39,97,46,108,0),
"T_1_3"=c(93,32,73,103,149,0,147,113,139),
"S_2_1"=c(69,67,94,0,77,136,137,92,73),
"S_2_2"=c(87,67,47,120,85,122,0,96,79),
"S_2_3"= c(150,0,132,121,29,78,109,40,0),
"T_1_0"= c(79,0,0,115,98,12,15,121,2)
)
df <- df %>% select(matches("^T_1_1"),-"T_1_0") %>% mutate(new1 = rowSums(matches("^T_1_1")!=0))