[R] Subset returning unexpected result

David Winsemius dwinsemius at comcast.net
Thu Oct 15 18:19:54 CEST 2009


On Oct 15, 2009, at 11:39 AM, Steve Murray wrote:

>
> Dear all,
>
> I am attempting to subset a data frame based on a range of latitude  
> values. I want to extract the values of 'interception' where  
> latitude ranges between 50 and 60. I am doing this using the  
> following code, yet it doesn't return the results I expected:
>
>
>> test <- subset(int1901, Latitude>=50 & Latitude <60,  
>> select=c(Latitude, Interception))
>
>
>> head(test)
>    Latitude Interception
> 2      6.25   0.04725863
> 3      6.75  67.02455139
> 82    50.75  51.74784088
> 83    51.25  57.04327774
> 84    51.75  51.51020432
> 85    52.25  53.30662537
>
>
> As you can see, latitude values outside the 50 to 60 range have been  
> retained (e.g. the top two rows of 'test'). Why is this, and how can  
> I ensure that I subset the data as initially intended?

What does str(int1901) show to be the type for Latitude? (I'm guessing  
it's a factor.)

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list