[R] Logical operators

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sun Jun 9 12:41:18 CEST 2002


On Sun, 9 Jun 2002, Patrick Hausmann wrote:

> Hello,
>
> I have a csv-file which looks like:
>
> #### pwt6_r.csv ####
> code;year;rgdpch
> AGO;1998;1234
> ALB;1998;3576
> ARG;1998;#NA
> SVN;1996;13439
> SWE;1996;21492
> AGO;1960;#NA
> ALB;1960;2345
> ARG;1960;4634
> #### pwt6_r.csv ####
>
> To import this file i call:
> pwt6<-read.csv("d:/pwt6_r.csv",header=T,na.strings="#NA",sep=";")
>
> Now I want to generate a new data.frame which include only
> + observations for the years 1960 and 1998
> + where the variable 'rgdpch' has no missing values.

pwt6[(pwt6$year %in% c("1996", "1998")) & !is.na(pwt6$rgdch), ]

if you actually meant the rows in which 'rgdpch' was not missing.

>
> The result should be:
>
> code;year;rgdpch
> ALB;1998;3576
> ALB;1960;2345
>
> I tried to solve this with logical operators (==), but without any
> success.

It can be done, and as you did not tell us what you tried, we cannot help
correct your misconceptions.

> Thanks for your help!
> Patrick
> -------------
> Patrick Hausmann
> Friedrich-Wilhelm Str. 37 - D-28199 Bremen
> Tel. +49 421 5980631 - Fax. +49 421 5980632
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list