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? Many thanks for any help offered, Steve
It would be useful to also post the 'str(int1901)' so that we could see the structure of the dataframe. Is Latitude by chance a 'factor'? You could also put a subset with the data by doing: dput(int1901) On Thu, Oct 15, 2009 at 11:39 AM, Steve Murray <smurray444 at hotmail.com> 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? > > Many thanks for any help offered, > > Steve > > > > ______________________________________________ > 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?
<77EB52C6DD32BA4D87471DCD70C8D70001F1196C at NA-PA-VBE03.na.tibco.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Dear Bill and all=2C Yep you were right - for some strange reason (I'm not sure how...)=2C the latitude data were of class 'character' instead of 'numeric'. I've put that right and that seems to have fixed it! Many thanks for your help=2C Steve =20
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
<FA3C85AC-06AB-4635-9642-8909552C0776 at comcast.net> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Bill=2C It seems to be 'character' - odd...!> str(int1901$Latitude)=A0chr [1:61537] "5.75" "6.25" "6.75" "7.25" "7.75" "8.25" ... Thanks again=2C Steve> What does str(int1901) show to be the type for Latitude? (I'm guessing > it's a factor.) > > -- > > David Winsemius=2C MD > Heritage Laboratories > West Hartford=2C CT >=20