[R] If Statement Help

jim holtman jholtman at gmail.com
Sun Oct 24 04:21:33 CEST 2010


Need to understand how 'indexing' is done in R:

> x <- read.table(textConnection("                   Price
+ 2010-10-11     99
+ 2010-10-12    101
+ 2010-10-13    102
+ 2010-10-14    103
+ 2010-10-15     99
+ 2010-10-18     98
+ 2010-10-19     97
+ 2010-10-20    101
+ 2010-10-21    101
+ 2010-10-22    101"), header = TRUE)
> closeAllConnections()
> x
           Price
2010-10-11    99
2010-10-12   101
2010-10-13   102
2010-10-14   103
2010-10-15    99
2010-10-18    98
2010-10-19    97
2010-10-20   101
2010-10-21   101
2010-10-22   101
> x[x$Price > 100,, drop = FALSE]
           Price
2010-10-12   101
2010-10-13   102
2010-10-14   103
2010-10-20   101
2010-10-21   101
2010-10-22   101
>


On Sat, Oct 23, 2010 at 9:56 PM, Jason Kwok <jaykwok at gmail.com> wrote:
>                    Price
> 2010-10-11     99
> 2010-10-12    101
> 2010-10-13    102
> 2010-10-14    103
> 2010-10-15     99
> 2010-10-18     98
> 2010-10-19     97
> 2010-10-20    101
> 2010-10-21    101
> 2010-10-22    101
>
> I have this dataset and I only want to return instances when the Price is >
> 100.
>
> If I use the code: Price > 100 then it will evaluate each entry as "TRUE" or
> "FALSE".  What is the code to only return "TRUE" results?
>
> Thanks,
>
> Jay
>
>        [[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 that you are trying to solve?



More information about the R-help mailing list