Calculate the percentage of zeros that I have in a column in R -
i have column of catch rate data in df (df$catch.rate) contains combination of decimal values , zeros. calculate percentage of 0 rows in whole column give me indication of contribution data.
many thanks!
sum(df$catch.rate %in% 0 ) / nrow(df)
i suggest using %in%
if have na
values..... e.g.
x <- c(0,na,1) sum(x == 0 ) / length(x) #[1] na
Comments
Post a Comment