当我尝试运行此代码时,标题中出现错误。我是一个初学者,不知道如何解决它。我已包含所有代码以供参考。 ggplot行之前的所有行似乎都可以工作,但最后一行会导致错误。
ClassStroopData_300 <- read_csv("ClassStroopData_300.csv")
Data300 <-ClassStroopData_300
mean(Data300$responseTime)
sd(Data300$responseTime)
Data300["WorkspaceVar1"] <- grepl("_",Data300$note)
WorkspaceVar1 that contains the info whether or not the column "note" contained a "_"
Data300["WorkspaceVar2"] <- grepl("text",Data300$content)
Data300["WorkspaceVar3"] <-grepl("red_red|blue_blue|green_green|orange_orange|purple_purple",Data300$content)
Data300["WorkspaceVar4"] <- grepl("4db78970c3816d3d|a8cc6a79046e188f|c21c48d74bc99a6|dd2942c485109f3e|5eb0fbeb9b0685e2",Data300$frameId)
Data300["incongruent"] <- Data300$WorkspaceVar1*2
Data300["instructions"] <- Data300$WorkspaceVar2*1
Data300["congruent"] <- Data300$WorkspaceVar3*3
Data300["practice"] <- Data300$WorkspaceVar4*10
Data300["condition sums"] <- Data300$incongruent + Data300$instructions + Data300$congruent + Data300$practice
Data300["condition"] <- factor(Data300$`condition sums`,levels = c("1","2","3","12"),labels = c("instructions","incongruent","congruent","practice"))
CongruentTrials <- subset(Data300, condition == "congruent")
mean(CongruentTrials$responseTime)
sd(CongruentTrials$responseTime)
IncongruentTrials <- subset(Data300, condition == "incongruent")
mean(IncongruentTrials$responseTime)
sd(IncongruentTrials$responseTime)
aggregate(Data300$responseTime,list(Data300$condition),mean)
aggregate(Data300$responseTime,list(Data300$condition),sd)
MICT <- mean(IncongruentTrials$responseTime)
SDICT <- sd(IncongruentTrials$responseTime)
MCT <- mean(CongruentTrials$responseTime)
SDCT <- sd(CongruentTrials$responseTime)
cbind(c(MICT,MCT), c(SDICT,SDCT))
table = cbind(c(MICT,MCT), c(SDICT,SDCT))
colnames(table) = c("mean","standard deviation")
rownames(table) = c("Incongruent", "Congruent")
t.test(IncongruentTrials$responseTime, CongruentTrials$responseTime, paired = T, var.equal = T)
library(ggplot2)
IncongruentNoOutliers <- subset(IncongruentTrials, responseTime < 1267.0660+401.6672*3.5 & responseTime > 1267.0660-401.6672*3.5)
CongruentNoOutliers <- subset(CongruentTrials, responseTime < 1009.4660+352.9656*3.5 & responseTime > 1009.4660-352.9656*3.5)
CongruentNoOutliers$Identify = "Congruent"
IncongruentNoOutliers$Identify = "Incongruent"
AllNoOutliers = rbind(CongruentNoOutliers, IncongruentNoOutliers)
ggplot(AllNoOutliers, aes(x=responseTime, fill=as.factor(identify))) + geom_histogram(alpha = 0.5, position = 'identity') + scale_fill_discrete(name="Trial Type")
答案 0 :(得分:0)
我编写了此示例代码,以说明您的ggplot行还可以:
PolicyNumber=2
检查responseTime <- sample(20:50, 200, TRUE)
identify <- sample(letters[1:2], 200, TRUE)
AllNoOutliers <- data.frame(responseTime, identify, stringsAsFactors = FALSE)
library(ggplot2)
ggplot(AllNoOutliers, aes(x=responseTime, fill=as.factor(identify))) +
geom_histogram(alpha = 0.5,
position = 'identity', binwidth = 20) +
scale_fill_discrete(name="Trial Type")
是否为class(AllNoOutliers$responseTime)
。