我正在尝试使用ddply函数创建数据摘要。 现在这个有用了,所以我真的很困惑,我没有改变代码中的任何东西(afaik),但这就是我所说的:
desc_df <- ddply(df, c("Condition", "stimCat"), summarise,
N = length(RT),
mean = mean(RT),
sd = sd(RT),
se = sd / sqrt(N))
这是我收到的错误消息:
Error in -------------------------------desc_df <- ddply(df, c("Condition", :
object 'desc_df' not found
这是我在没有'desc_df&lt; - '
的情况下输入的内容 Condition stimCat N mean sd se
1 NA NA -1080 -846.9602 -502.1748 -15.280694
2 NA NA -2160 -871.5088 -542.4716 -11.672131
3 NA NA -3240 -818.8568 -526.7179 -9.253491
以同样的方式添加更多行
这是我发现的接近这个: Object not found error with ddply inside a function 但它没有帮助,或者我不理解它。 Jorens的回答(11月5日在13:47回答)说了一些关于ddply和总结的问题,但我不确定它与创建一个对象有什么关系。 (我不能说,因为我对R很新)
如何使用其中的摘要创建该对象,而不会出现错误。
感谢您的帮助!
在评论的帮助下,我能够以这种方式创建我需要的东西:我使用了zx8754中使用mtcars数据集的代码。 有效。 现在我用他的名字交换了代码中的每一部分。 有效。
所以看起来像这样
desc_df <- ddply(df, c("Condition", "stimCat"), summarise,
N = length(RT),
mean = mean(RT),
sd = sd(RT),
se = sd / sqrt(N))
desc_df <- ddply(df, c("Condition", "stimCat"), summarise,
N = length(RT),
mean = mean(RT),
sd = sd(RT),
se = sd / sqrt(N))
第一个版本会产生错误,第二个版本不会产生错误。但无论我多么努力寻找差异,我都无法......
当我这样做时
dput(head(df))
我明白了:
structure(list(Condition = structure(c(1L, 1L, 1L, 1L, 1L, 1L
), .Label = c("Goal", "Plan"), class = "factor"), Target = structure(c(1L,
1L, 1L, 1L, 1L, 1L), .Label = c("emptRectangle", "emptTriangle"
), class = "factor"), Subject = structure(c(101L, 101L, 101L,
101L, 101L, 101L), .Label = c("1", "2", "3", "4", "5", "6", "7",
"8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40",
"41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51",
"52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62",
"63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73",
"74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84",
"85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95",
"96", "97", "98", "99", "100", "101", "102", "103", "104", "105",
"106", "107", "108", "109", "110", "111", "112", "113", "114",
"115", "116", "117", "118", "119", "120", "121", "122", "123",
"124", "125", "126", "127", "128", "129", "130", "131", "132",
"133", "134", "135", "136", "137", "138"), class = "factor"),
Block = c(100, 101, 102, 103, 104, 105), Filling = structure(c(2L,
1L, 2L, 1L, 2L, 1L), .Label = c("empt", "fill"), class = "factor"),
Shape = structure(c(1L, 1L, 2L, 1L, 1L, 1L), .Label = c("Rectangle",
"Triangle"), class = "factor"), Type = structure(c(2L, NA,
NA, 2L, NA, 1L), .Label = c("L", "W"), class = "factor"),
Stimulus = structure(c(9L, 1L, 10L, 3L, 7L, 2L), .Label = c("emptRectangle",
"emptRectangleL", "emptRectangleW", "emptTriangle", "emptTriangleL",
"emptTriangleW", "fillRectangle", "fillRectangleL", "fillRectangleW",
"fillTriangle", "fillTriangleL", "fillTriangleW"), class = "factor"),
Response = c(1, 1, 1, 1, 0, 1), RT = c(2036, 713, 690, 995,
667, 5137), stimCat = structure(c(3L, 1L, 4L, 2L, 3L, 2L), .Label = c("Target",
"SsR", "SsRd", "SdR", "SdRd"), class = "factor"), logRT = c(7.61874237767041,
6.5694814204143, 6.5366915975913, 6.90274273715859, 6.50279004591562,
8.54422453046727), outlier = c(1, 0, 0, 0, 0, 1)), .Names = c("Condition",
"Target", "Subject", "Block", "Filling", "Shape", "Type", "Stimulus",
"Response", "RT", "stimCat", "logRT", "outlier"), row.names = c(NA,
6L), class = "data.frame")