Hi,

I think it's a FAQ (== vs all.equal to test for equality), and not related to expand.grid. See ?all.equal and ?"=="

You don't need which, gridd[gridd[,2]=="0.6" , ] would work fine, or more elegantly (imho),

gridd <- expand.grid(x=x,y=y )

subset(gridd, factor(x) == "0.6")


Hope this helps,

baptiste

On 7 Apr 2009, at 15:35, stefan.d...@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)

______________________________________________
R-help@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.

_____________________________

Baptiste AuguiƩ

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

______________________________________________
R-help@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.

Reply via email to