Message-ID: <1296179467675-3243583.post@n4.nabble.com>
Date: 2011-01-28T01:51:07Z
From: Pete Brecknock
Subject: sapply puzzlement
In-Reply-To: <0CD56172-E028-47BF-8F15-93ADE8EDEBA4@comcast.net>
In addition to what has already been suggested you could use ......
mapply(function(x,y) x-y, z,means)
which returns ....
V1 V2
[1,] 0.3333333 -2.7142857
[2,] NA 7.2857143
[3,] -0.6666667 -3.7142857
[4,] -6.6666667 NA
[5,] NA -0.7142857
[6,] 1.3333333 1.2857143
[7,] 3.3333333 -1.7142857
[8,] 2.3333333 0.2857143
The results you see when you use the z-means approach are caused by the
vectors being different lengths. The shorter one (means) is repeated.
Phil Spector's book describes a nice example which illustrates the behaviour
nicely.
nums = 1:10
nums +c(1,2)
HTH
Pete
--
View this message in context: http://r.789695.n4.nabble.com/sapply-puzzlement-tp3243520p3243583.html
Sent from the R help mailing list archive at Nabble.com.