开发者

How do I create a similarity matrix using R with my own data?

I have a study where I presented pairs of stimuli and the individual recorded a response (numbers 1-1-1000). I would like the name of stimulus one on the x axis, the name of stimulus 2 on the y axis and the response recorded according 开发者_StackOverflow社区to the corresponding pair presented. Right now I only have my data in columns: column 1 trial number, column 2 name of stim 1, column 3 name of stim 2, and column 4 the response. Any advice? How could I go about this using R?


darckeen's post just needs to have list() instead of c(). Then I think it should work. Here's a full example:

set.seed(12345)
data = expand.grid(trial=1:10, stim1=1:5, stim2=1:3)
data = data.frame(data, response=rnorm(nrow(data)))

with(data, tapply(response, list(stim1,stim2), mean))

Output:

            1           2           3
1 -0.13294415  0.27326245 -0.11120045
2  0.28597776  0.02338804  0.21280916
3  0.08338741  0.44086561 -0.08682628
4  0.72432003  0.84250712  0.28383378
5 -0.06290978 -0.02588252 -0.36364019

(BTW sorry to make a new answer. I don't have enough reputation to comment yet and the edit is too small to apply directly to the previous post.)


If understand the question correctly this should work:

mydata <- data.frame(trial,stim1,stim2,response)

mytable <- tapply(mydata$response,list(mydata$stim1,mydata$stim2),mean)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜