[R] Making cuts on multivariate data

David Winsemius dwinsemius at comcast.net
Mon Aug 30 07:04:15 CEST 2010


On Aug 30, 2010, at 12:57 AM, David Winsemius wrote:

>
> On Aug 29, 2010, at 10:50 PM, Erik Ramberg wrote:
>
>> I'm a newbie to R and  I was hoping someone could answer a simple  
>> question.  I want to read in an ASCII file with 3 columns - x,y,z.   
>> Let's say there is a lot of data - 100,000 entries.  I then want to  
>> histogram x values that pass arbitrary (and complicated) cuts on y  
>> and/or z.  Likewise, I want to make a scatterplot with x and y,  
>> with a cut on z values.  Perhaps you have to redefine the vectors  
>> first.
>>
>> I'm thinking along the lines of
>> hist(x) for y>0 .and. sqrt(z)<4
>
> If the data is in a dataframe named dta with columns x,y, and z then:
>
> with( dta[which( dta$y > 0 & sqrt(z) < 4), ],
>        hist(x)  )
>
Should be:
with( dta[which( dta$y > 0 & sqrt(dta$z) < 4), ],

         hist(x)  )

>>
>> or
>>
>> plot(x,y) for x>0 .and. y>0 .and.z**2 > 100
>
> The strategy generalizes.
>
>>
>> I cant find this simple task in a first perusal of some of the  
>> tutorials.
>
>> Any suggestions you could give would be helpful.
>
> Don't forget to read the Posting Guide.
>>
>
> -- 
> David.



More information about the R-help mailing list