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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -