apply problem
apply(iris3,1,function(x)identical(x,iris3[1,]))
1 2 3 FALSE FALSE FALSE What's wrong here?
iris3 is not an array, so it it coerced to one via as.matrix
[...]
and that's not the same object as your iris3
Is there a way to iterate over the rows of a data frame without writing a loop -- that was my original objective.
No. A row of a data frame is still a data frame and therefore arbitrarily complex.
OK. Efficiency aside,I believe it would still be nice to have this ability for compactness. Here are some ideas: 1. Have an option on t(), the transpose function, that specifies that it should return a list of one row data frames. The above becomes: sapply( t(iris3,list.out=T), function(x) identical( x, iris3[1,] ) ) 2. Allow dist() to have two arguments and a distance function that is 0 for identical rows and 1 for others (or even allow user specifiable distance functions). The above becomes: dist(iris3[1,],iris3,method="identical") or with user specifiable distance functions: dist(iris3[1,],iris3,user.method=identical) 3. Have a right crossprod such that crossprod(a,b,right=T) is the same as a+.*t(b) and also user specifiable inner products: crossprod(iris3,iris3[1,],inner.prod=identical) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._