R dataframe 统计每行中大于某个值的列的数量

统计每行的yes的个数

isA=c("yes","no","yes",NA)
isB=c("no","yes","no",NA)
df <- data.frame(isA,isB)
df

   isA  isB
1  yes   no
2   no  yes
3  yes   no
4 <NA> <NA>


df$ans<-apply(df,1,function(x) table(x)["yes"])
df
   isA  isB ans
1  yes   no   1
2   no  yes   1
3  yes   no   1
4 <NA> <NA>  NA

REF

https://bbs.pinggu.org/thread-3978012-1-1.html

https://bbs.pinggu.org/forum.php?mod=viewthread&tid=6875101&page=1

------------------------------------------

dataframe某列满足特定值的数量

1. df[df["val"]==0].id.count()

2. len(df[df["val"]==0])

REF

https://blog.csdn.net/qq_41973062/article/details/111224007

------------------------------------------

 isA=c(1,2,3,NA)
isB=c(11,12,13,NA)
df <- data.frame(isA,isB)
df
  isA isB
1   1  11
2   2  12
3   3  13
4  NA  NA
 

df$ans<-apply(df,1,function(x) sum(x>=1))
df
  isA isB ans
1   1  11   2
2   2  12   2
3   3  13   2
4  NA  NA  NA

 ------------------------------------------

原文地址:https://www.cnblogs.com/emanlee/p/14878523.html