Thanks Esawi,Barradas and Berger Sincerely Engin YILMAZ
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> Virus-free. www.avast.com <https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> 2017-10-29 23:14 GMT+03:00 Ek Esawi <esaw...@gmail.com>: > What was suggested by Eric and Rui works well, but here is a short and > may be simpler answer provided your data is similar what Eric posted. It > should work for your l data too. > > aa <- is.na(data)|data==0 > nrow(data)-colSums(aa) > > EK > > On Sun, Oct 29, 2017 at 6:25 AM, Engin YILMAZ <ispanyol...@gmail.com> > wrote: > >> Dear R Staff >> >> You can see my data.csv file in the annex. >> >> I try to count non-zero values in dataset but I need to exclude NA in this >> calculation >> >> My code is very long (following), >> How can I write this code more efficiently and shortly? >> >> ## [NA_Count] - Find NA values >> >> data.na =sapply(data[,3:ncol(data)], function(c) sum(length(which(is.na >> (c))))) >> >> >> ## [Zero] - Find zero values >> >> data.z=apply(data[,3:ncol(data)], 2, function(c) sum(c==0)) >> >> >> ## [Non-Zero] - Find non-zero values >> >> data.nz=nrow(data[,3:ncol(data)])- (data.na+data.z) >> >> >> Sincerely >> Engin YILMAZ >> >> <https://www.avast.com/sig-email?utm_medium=email&utm_source >> =link&utm_campaign=sig-email&utm_content=webmail> >> Virus-free. >> www.avast.com >> <https://www.avast.com/sig-email?utm_medium=email&utm_source >> =link&utm_campaign=sig-email&utm_content=webmail> >> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> >> ______________________________________________ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posti >> ng-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > -- *Saygılarımla* Engin YILMAZ [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.