I have a DF catch rate data column (df $ catch.rate) that contains a combination of decimal values ββand zeros.
I would like to calculate the percentage of null rows in the entire column to give me an idea of ββtheir contribution to the data.
sum(df$catch.rate %in% 0 ) / nrow(df)
I suggest using %in% if you have values NA ..... for example
%in%
NA
x <- c(0,NA,1) sum(x == 0 ) / length(x) #[1] NA
mean(!df$catch.rate)
will do the trick. You can add an argument na.rm = TRUE if there is NA s.
na.rm = TRUE
nrow(df[df$catch.rate == 0,])/nrow(df)
sum(df$catch.rate==0)/length(df$catch.rate)
There is probably a more R-ish way, but this is the fastest I could think of with.