[R] Plotting using 'if' statements

Steve Murray smurray444 at hotmail.com
Fri Sep 5 13:52:36 CEST 2008


Sorry! Hopefully just one more question!

I'm now trying to plot columns 3 and 6. I've tried:

> plot(January[3:6])

...but this plots columns 4 and 5 too!


I've also tried:

> plot(January[3],January[6])
> plot(January[3,6])
> plot(January[3]:January[6])

But these don't produce the right results (instead, errors!)

Again, I'm sure it's a just a small (but important) detail that I'm missing, and I'd be very grateful if anyone could help me out.

Many thanks again,

Steve

________________________________
Date: Thu, 4 Sep 2008 13:52:03 -0300
From: wwwhsd at gmail.com
To: smurray444 at hotmail.com
Subject: Re: [R] Plotting using 'if' statements
CC: r-help at r-project.org

Use '&':

plot(January[January[,3]> 0 & January[,3] < 2, 3:4])

On Thu, Sep 4, 2008 at 1:47 PM, Steve Murray  wrote:



Ah that's great, thank you very much.



As a follow-on, in the same format, how would I plot where column 3 is greater than 0 *but also less than 2*?



Once again, any help is much appreciated.





Thanks,



Steve



________________________________

Date: Thu, 4 Sep 2008 13:39:12 -0300

From: wwwhsd at gmail.com

To: smurray444 at hotmail.com

Subject: Re: [R] Plotting using 'if' statements

CC: r-help at r-project.org



Try this:



plot(January[January[,3]> 0, 3:4])



On Thu, Sep 4, 2008 at 1:28 PM, Steve Murray  wrote:











Dear all,







I have a dataset of four columns, and I wish to plot (as a scatter graph) the values of the third column where the values are greater than zero, and the fourth column.







I tried doing this via the plot command itself, but got into a bit of a mess (resulting in errors!). My dataframe is called 'January':







> plot(January[3(>0):4])



Error: unexpected '>' in "plot(January[3(>"











After a few variations on this, I thought I'd try making a new object which includes all values from the third column of January>0 (to plot in a separate step) as follows:







> JanFilter <- January[3]>0







No error here. However, when I display the 'values' of JanFilter, it shows that instead of keeping the numerical values, the above operation simply displays the results of the logical test:







> head(JanFilter)



                           Value



[1,]                       FALSE



[2,]                        TRUE



[3,]                        TRUE



[4,]                        TRUE



[5,]                        TRUE



[6,]                        TRUE











[[elided Hotmail spam]]







So my question is, how do I perform 'if' statements in order to filter out various parts of a dataset, for plotting on a graph.







Many thanks,







Steve







______________________________________________



R-help at r-project.org mailing list







PLEASE do read the posting guide http://www.R-project.org/posting-guide.html



and provide commented, minimal, self-contained, reproducible code.









--

Henrique Dallazuanna

Curitiba-Paraná-Brasil

25° 25' 40" S 49° 16' 22" O







_________________________________________________________________







--
Henrique Dallazuanna
Curitiba-Paraná-Brasil

25° 25' 40" S 49° 16' 22" O



_________________________________________________________________
Win New York holidays with Kellogg’s & Live Search



More information about the R-help mailing list