[R] Subtraction with aggregate
Jim Lemon
drjimlemon at gmail.com
Fri Jul 29 02:07:31 CEST 2016
Hi Gang,
This is one way:
gangdat<-read.table(text="subject QM emotion yi
s1 75.1017 neutral -75.928276
s2 -47.3512 neutral -178.295990
s3 -68.9016 neutral -134.753906
s1 17.2099 negative -104.168312
s2 -53.1114 negative -182.373474
s3 -33.0322 negative -137.420410",
header=TRUE)
library(prettyR)
gangstretch<-stretch_df(gangdat,"subject",c("emotion","yi"))
gangstretch$emodiff<-gangstretch$yi_2-gangstretch$yi_1
gangstretch$emodiff
Jim
On Fri, Jul 29, 2016 at 6:40 AM, Gang Chen <gangchen6 at gmail.com> wrote:
> With the following data in data.frame:
>
> subject QM emotion yi
> s1 75.1017 neutral -75.928276
> s2 -47.3512 neutral -178.295990
> s3 -68.9016 neutral -134.753906
> s1 17.2099 negative -104.168312
> s2 -53.1114 negative -182.373474
> s3 -33.0322 negative -137.420410
>
> I can obtain the average between the two emotions with
>
> mydata <- read.table('clipboard', header=TRUE)
> aggregate(mydata[,c('yi', 'QM')], by=list(subject=mydata$subject), mean)
>
> My question is, what is a nice way to get the difference between the
> two emotions?
>
> Thanks,
> Gang
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list