Re: [R] basics on dataframes

From: jim holtman <jholtman_at_gmail.com>
Date: Sat, 05 Apr 2008 20:24:57 -0500

You must add a check for the NAs:

> a[(a$V1 > 1) & (!is.na(a$V1)),]

   V1 V2 V3 V4 V5 7 100 -2.343761 -132.6063 101.7575 1.187004

On Sat, Apr 5, 2008 at 8:05 PM, Georg Ehret <georgehret_at_gmail.com> wrote:
> Dear R community,
> I am using a dataframe with lots of NAs and wish to create subsets from
> that dataframe. In the example below I intend to create a subset with all
> entries with V1>1. To my surprise the result also contains all entries with
> V1=NA. I would wish to learn more why this is or what I do wrong. I know
> that I can use the command "subset" and the NAs will not appear, but what is
> "wrong" with a[a$V1>1,]?
> Thank you!
> Georg.
> *******************
> Georg Ehret
> Johns Hopkins
> Baltimore, USA
>
>
> > a
> V1 V2 V3 V4 V5
> 1 NA NA NA -2056.5981 0.8472496
> 2 NA NA NA 1407.8786 1.3349255
> 3 NA NA NA 579.2203 0.6082337
> 4 NA NA NA 1337.0740 1.0346453
> 5 NA NA -3.732253 -246.7270 1.9218894
> 6 NA -4.111501 -50.372053 -1512.2618 -0.8425137
> 7 100.0000000 -2.343761 -132.606282 101.7575 1.1870040
> 8 -1.8899018 11.921323 15.988519 -1199.5994 0.1907434
> 9 0.4819706 5.677561 29.677330 -200.9182 -0.1213408
> 10 -1.4981107 6.224487 209.133480 188.8852 -1.3321220
> > b<-a[a$V1>1,]
> > b
> V1 V2 V3 V4 V5
> NA NA NA NA NA NA
> NA.1 NA NA NA NA NA
> NA.2 NA NA NA NA NA
> NA.3 NA NA NA NA NA
> NA.4 NA NA NA NA NA
> NA.5 NA NA NA NA NA
> 7 100 -2.343761 -132.6063 101.7575 1.187004
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
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.
Received on Sun 06 Apr 2008 - 01:29:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 06 Apr 2008 - 01:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive