Repeated-Measures ANOVA: how to locate the significant difference(s) by R? I am trying to use R to run Repeated-Measures ANOVA. Based on the data from: 
https://www.youtube.com/watch?v=VPB3xrsFl4o&list=PL568547ACA9211CCA&index=75

The inputs in R are:
anxiety = c(9,8,7,8,8,9,8,7,6,6,7,8,7,6,4,3,2,3,4,3,2) 
time = c(rep("Before",7), rep("Week_1",7), rep("Week_2",7)) 
person = c(rep(c("Person_1","Person_2","Person_3","Person_4","Person_5","Person_6","Person_7"),3))
anxiety_data = data.frame(person, anxiety, time)

I think I should use aov() function in this way:
Repeated_Measures_ANOVA = aov(anxiety ~ time + Error(person/time), data=anxiety_data)

Can I ask if the code is correct?
As the TukeyHSD() function could not work
> TukeyHSD(Repeated_Measures_ANOVA, conf.level = 0.95)
Error in UseMethod("TukeyHSD") : 
no applicable method for 'TukeyHSD' applied to an object of class "c('aovlist', 'listof')"

can I ask how to determine where the significant difference is if positive result is obtained?    
 A: Once you use the Error() function within aov(), the resulting object is of class 'aovlist' and 'listof':
> class(Repeated_Measures_ANOVA)
[1] "aovlist" "listof"

See also ?aov under 'Details' and 'Value'
TukeyHSD() requires an object of class 'aov' in order to work (see ?TukeyHSD).
One way to navigate around this problem is to use a linear mixed-effects model. There are two main options. The one I show here uses the lmer() function from the lme4 package. Check here for a different way using the lme() function and ghlt() function from the multcomp package to get Tukey adjusted multiple mean comparisons.
require(lme4)
lmer.fit <- lmer(anxiety ~ time + (1|person), data = anxiety_data)
summary(lmer.fit)

To get p-values for your fixed effect time you could use the mixed function from the afex package (make sure to check ?mixed so that you know what the options are!)
require(afex)
mixed(anxiety ~ time + (1|person), data = anxiety_data) 

Then for Tukey adjusted multiple mean comparisons, you could use the lsmeans package:
require(lsmeans)
lsmeans(lmer.fit, pairwise~time, adjust="tukey")

