# [R] Counting NA?

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Oct 23 12:14:47 CEST 2002

On Wed, 23 Oct 2002, Matej Cepl wrote:

> Hi,
>
> how to do quickly equivalent of the following?
>
> 	counter = 0
> 	for(i in 1:length(data$S2)) { > if(!is.na(data$S2[i])) {
> 			counter = counter + 1
> 		}
> 	}
>
> I have imagined something like length(x,na.rm=TRUE).

sum(is.na(data$s2)), using that the fact that TRUE/FALSE are coerced to 1/0. > How can I get values usually taken from tables like z-score, > values of t distribution etc.? I could not find them among > values mentioned in info file. Use qnorm/pnorm etc. Here's the examples from chapter 1 of MASS4 (a good reference!) The \s. environment includes the equivalent of a comprehensive set of statistical tables; one can work out$P$values or critical values for a wide range of distributions (see Table~\ref{tab:dist.1} on page~\pageref{tab:dist.1}). \begin{session} 1 - pf(4.3781, 4, 76)&$P\$ value from the ANOVA table above.\cr
qf(0.95, 4, 76)&corresponding 5\% critical point.\cr
\end{session}

In R you could also use

pf(4.3781, 4, 76, lower.tail=FALSE)

although I tend to find that too much typing.

--
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._