Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread David L Carlson
17, 2015 3:57 PM To: Bert Gunter Cc: r-help Subject: Re: [R] Strange result when subsetting a data frame based on a character variable > On 17 Nov 2015, at 20:37 , Bert Gunter <bgunter.4...@gmail.com> wrote: > >> 2 == "2" > [1] TRUE > > ?"=="

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Bert Gunter
tment of Anthropology > Texas A University > College Station, TX 77840-4352 > > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard > Sent: Tuesday, November 17, 2015 3:57 PM > To: Bert Gunter > Cc: r-help > Su

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Bert Gunter
> 2 == "2" [1] TRUE ?"==" says: "If the two arguments are atomic vectors of different types, one is coerced to the type of the other, the (decreasing) order of precedence being character, complex, numeric, integer, logical and raw." > as.character(9) [1] "9" > as.character(10) [1]

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Thierry Onkelinx
Dear Karl, Since you compare a character with a numeric, R converts the numeric silently. And then you're into trouble. as.character(9) # "9" as.character(10) # "1e+5" Bottom line, use the same type on both sides of the binary operator. Best regards, ir. Thierry Onkelinx

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Thierry Onkelinx
Dear Duncan, I'd rather convert the numeric to character. E.g. with sprintf() or format() in case it is a numeric vector. subset(Data, group == "10") subset(Data, group == sprintf("%.f", 10)) sprintf("%.f", 10) # "10" It requires the user to think about the format, which can

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Conklin, Mike (GfK)
hael Conklin EVP Marketing & Data Sciences GfK T +1 763 417 4545 | M +1 612 567 8287 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Karl Schilling Sent: Tuesday, November 17, 2015 1:14 PM To: r-help@r-project.org Subject: [R] Strange result when

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Jeff Newmiller
Are you sure that wasn't oh-3 rather than 03? --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go...

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread peter dalgaard
> On 18 Nov 2015, at 01:59 , Jeff Newmiller wrote: > > Are you sure that wasn't oh-3 rather than 03? Sure I'm sure. I even cut+pasted the filenames from the offending dir... It's all just Apple trying to be helpful (and failing, again). O2 < 2d < O3 had been even

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Jim Lemon
peter dalgaard wrote: > O2 < 2d < O3 had been even stranger, no? Don't give those dudes in Cupertino any more bright ideas, okay? Jim On Wed, Nov 18, 2015 at 12:11 PM, peter dalgaard wrote: > > > On 18 Nov 2015, at 01:59 , Jeff Newmiller > wrote:

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Duncan Murdoch
On 17/11/2015 2:14 PM, Karl Schilling wrote: Dear all, I have one observation that I do not quite understand. Maybe someone can clarify this issue for me. I have a data frame which I want to subset based on a grouping variable, say "group". Actually, "group" is a numeric value, but it is saved

[R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Karl Schilling
Dear all, I have one observation that I do not quite understand. Maybe someone can clarify this issue for me. I have a data frame which I want to subset based on a grouping variable, say "group". Actually, "group" is a numeric value, but it is saved as a character. I give some code to

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread Duncan Murdoch
On 17/11/2015 2:25 PM, Duncan Murdoch wrote: On 17/11/2015 2:14 PM, Karl Schilling wrote: > Dear all, > > I have one observation that I do not quite understand. Maybe someone > can clarify this issue for me. > > I have a data frame which I want to subset based on a grouping variable, > say

Re: [R] Strange result when subsetting a data frame based on a character variable

2015-11-17 Thread peter dalgaard
> On 17 Nov 2015, at 20:37 , Bert Gunter wrote: > >> 2 == "2" > [1] TRUE > > ?"==" says: > > "If the two arguments are atomic vectors of different types, one is > coerced to the type of the other, the (decreasing) order of precedence > being character, complex,