Count number of rows matching a criteria

后端 未结 8 881
渐次进展
渐次进展 2020-11-29 05:01

I am looking for a command in R which is equivalent of this SQL statement. I want this to be a very simple basic solution without using complex functions OR dplyr type of pa

8条回答
  •  借酒劲吻你
    2020-11-29 05:25

    sum is used to add elements; nrow is used to count the number of rows in a rectangular array (typically a matrix or data.frame); length is used to count the number of elements in a vector. You need to apply these functions correctly.

    Let's assume your data is a data frame named "dat". Correct solutions:

    nrow(dat[dat$sCode == "CA",])
    length(dat$sCode[dat$sCode == "CA"])
    sum(dat$sCode == "CA")
    

提交回复
热议问题