[R] strange (?) behavoir of expand.grid()
David Winsemius
dwinsemius at comcast.net
Tue Apr 7 16:53:37 CEST 2009
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
--
David Winsemius
On Apr 7, 2009, at 10:35 AM, stefan.duke at gmail.com wrote:
> Hello,
>
> I came across a strange behavior of expand.grid (or at least strange
> to me).
>
> For certain values of one of my input variables - created by seq() - I
> have to use strings (e.g ==".6") to select a row of the object
> created by expand.grid(), for other values numerical (e.g. ==.8) and
> for some both work. Please find an example below.
>
>
> #Example
> x<- seq(0,1,1/10)
> y <- seq(0,1,1/10)
>
> gridd <- expand.grid(x,y )
>
>
> gridd[which( gridd[,2]=="0.6" ),] #gives me the right data
> gridd[which( gridd[,2]==0.6 ) ,] #gives error message
>
> gridd[which( gridd[,2]=="0.4" ),] #gives right data
> gridd[which( gridd[,2]==0.4 ),] #gives right data
>
> gridd[which( gridd[,2]=="0.0" ),] #gives error message
> gridd[which( gridd[,2]==0.0 ),] #gives me the right data
> #End of Example
>
>
> I also encountered this phenomenon on another version of R and on
> another computer.
>
> Has anybody an idea what this is and how to overcome it?
>
> Best,
> Stefan
>
>
>
> Sys.getlocale()
> [1] "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United
> Kingdom.1252;LC_MONETARY=English_United
> Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"
>
> version
> _
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 8.0
> year 2008
> month 10
> day 20
> svn rev 46754
> language R
> version.string R version 2.8.0 (2008-10-20)
More information about the R-help
mailing list