Re: [R] adding counter to df by group

2017-05-04 Thread Davide Piffer
Thanks David! I tried this but didn't work. Got a bunch of warning messages: Warning messages: 1: In `[<-.factor`(`*tmp*`, i, value = 1:52) : On 4 May 2017 at 02:23, David Winsemius wrote: > >> On May 3, 2017, at 11:24 AM, Davide Piffer wrote: >> > > You should look at this result more closely.

Re: [R] adding counter to df by group

2017-05-03 Thread David Winsemius
> On May 3, 2017, at 11:24 AM, Davide Piffer wrote: > You should look at this result more closely. Its length is not the same length as the number of rows of the target of the attempted assignment. > unlist(miniblock_cong) You might try: red_congruent$miniblock <- ave( red_congruent$subject

Re: [R] adding counter to df by group

2017-05-03 Thread Jim Lemon
Hi Davide, You wouldn't be dealing with the Stroop test, would you? stroop.df<-data.frame(subject=rep(paste("S",1:10,sep=""),each=12), color=rep(c("R","G","B"),40),cong=rep(rep(c("C","I"),each=3),20)) stroop.df$colcong<-paste(stroop.df$color,stroop.df$cong,sep="") stroop.rc<-stroop.df[stroop.df$c

[R] adding counter to df by group

2017-05-03 Thread Davide Piffer
I need to count the trials in an experiment, separately for each subject. I thought about using the function "by" but I could not manage to achieve this. Instead, I tried "split" and I got closer to a solution but still not getting there yet. The following code should create a variable "miniblock"