[R] A function taken out of its original environment performs more slowly.

2013-08-17 Thread Xiao He
Hi dear R-users, I encountered an interesting pattern. Take for example the function combn(), I copied and pasted the function definition and saved it as a new function named combn2() (see the end of this email). As it turned out, combn2() seems to be substantially slower than the original functio

Re: [R] Sum first 3 non zero elements of row

2013-05-21 Thread Xiao He
That's a good one, Using cumsum + rowsum would definitely be faster, On Tue, May 21, 2013 at 6:40 AM, José Verhoeven wrote: > Thank you, that really worked. Actually received an even shorter version: > > > rowSums((t(apply(D > 0, 1, cumsum)) <= 3) * D) > > > &

Re: [R] Sum first 3 non zero elements of row

2013-05-21 Thread Xiao He
) #add a right parenthesis. mat On Tue, May 21, 2013 at 3:47 AM, Xiao He wrote: > Does this work? Probably not the fastest, but I think it does the job. > > foo<-function(x){ > temp=x[x>0] > if(length(temp)>=3) sum(temp[1:3]) > else sum(temp) > > set.seed(2)

Re: [R] Sum first 3 non zero elements of row

2013-05-21 Thread Xiao He
Does this work? Probably not the fastest, but I think it does the job. foo<-function(x){ temp=x[x>0] if(length(temp)>=3) sum(temp[1:3]) else sum(temp) set.seed(2) mat<-matrix(sample(0:4, 25, replace=T, prob=c(1/2,rep(1/8,4)), ncol=5) mat # [,1] [,2] [,3] [,4] [,5] #[1,]012

[R] How many decimal places of information does R actually use in computation?

2013-05-20 Thread Xiao He
Dear R-users: Hi, I read here ( http://stackoverflow.com/questions/2287616/controlling-digits-in-r) that R is only accurate up to the 15th decimal place, despite the fact that if you choose to display more decimal places, it will. I wonder if R uses the information beyond the 15th decimal place in

[R] Help with Post-Hoc tests for TWO-WAY within subject ANOVA

2010-06-09 Thread Xiao He
Dear R users, I posted a couple of questions and got no response, so I am giving it another shot. I ran an experiment with a TWO-WAY within subject design. A sample dataset is in http://www-scf.usc.edu/~hex/data.txt I already ran ANOVA by using the following formula: aov(RT~Factor1*Factor2 + Er

Re: [R] Why did TukeyHSD not work when I used it for post-hoc for 2way within-subjects anova?

2010-06-06 Thread Xiao He
Sorry, that in the last message the tables were messed up. Here is a link to the tables http://www-scf.usc.edu/~hex/data.txt <http://www-scf.usc.edu/~hex/data.txt>Thanks! On Sun, Jun 6, 2010 at 10:18 AM, Xiao He wrote: > Dear R people, > > I have a couple of questions about po

[R] Why did TukeyHSD not work when I used it for post-hoc for 2way within-subjects anova?

2010-06-06 Thread Xiao He
Dear R people, I have a couple of questions about post-doc analyses for 2 by 2 within subjects ANOVA. I conducted a psycholinguistic study that combined a 2 by 2 design and a latin square design. Specifically, I had 32 items each of which generated 4 conditions. Participants saw each of the 32 ite