# [R] Loop removal?

rijn@swi.psy.uva.nl rijn at swi.psy.uva.nl
Mon Jul 31 15:52:37 CEST 2000

Hi,

thanks to all who responded to my question. The various responses teached
me, again, a lot about R and the different philosophy of R compared to
programming languages. Especially the reply of Peter Malewski using the
tapply/unlist/rep functions was very insightful, and helped me to solve my
problems.

To explain why I needed this all: in a lexical decision (psychonomy)
experiment, the subjects had to respond at several predefined lags.
However, the response times show quite some variation, so besides an
analysis based on the 6 predefined lags, we also wanted to do an analysis
based on 6 groups each containing 1/6th of the fastest, slowest, etc RTs
per subject.

So, in the orginial dataframe, we had the columns subject, lag and rt, and
the code I posted in my last message was meant to add the column binlag.

subject  lag   rt     binlag
1        1     350    1
1        1     450    2
1        2     425    1
1        2     475    2
2        1     425    1
2        1     450    1
2        2     490    2
2        2     480    2
.
.

Sorry if I was unclear in my previous postings. Again, thanks for all the
help!

Hedderik.

P.S. The code I use now, is:

bin.index <- function(data,bins=2) {
# Code from Peter Malewski, added the sort command.
sort(rep(rep(1:bins,rep(length(data)/bins,bins)),length.out=length(data)))
}

cat("Binning...")
stor <- stor[order(stor\$subject,stor\$rt),]
stor\$binlag <- unlist(tapply(stor\$rt,stor\$subject,bin.index,bins=6))
print("done")

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._