1

I am trying to create a summary of my data with the ddply function. Now this has worked before, so I am really confused, I didn't change anything in the code (afaik), but this is what I put in:

desc_df <- ddply(df, c("Condition", "stimCat"), summarise,
           N    = length(RT),
           mean = mean(RT),
           sd   = sd(RT),
           se   = sd / sqrt(N))

And this is the error message I get:

Error in -------------------------------desc_df <- ddply(df, c("Condition",  : 
object 'desc_df' not found

This is what comes out when I give the input without 'desc_df <-'

   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

and some more lines in the same fashion

This is what I found close to this: Object not found error with ddply inside a function but it doesn't help or I don't understand it right. Jorens answer (answered Aug 5 '11 at 13:47) says something about problems with ddply and summarize, but I am not sure it has something to do with creating an object. (I cant tell though, as I am pretty new to R)

How can I create that object with the summary in it, without getting an error.

Thank you for your help!

With the help from the comments I was able to create what I needed in this way: I used the code from zx8754 which was using the mtcars dataset. It worked. Now I exchanged every part in his code with the names in mine. It worked.

So it looks like this

    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))

The first version creates an error, the second doesnt. But no matter how much I try to find differences, I cant...

When I do

dput(head(df))

I get:

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")
Manik
  • 11
  • 3
  • 2
    Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Jan 17 '18 at 11:53
  • what happens if you execute without the `desc_df <- `? – drmariod Jan 17 '18 at 12:02
  • @zx8754 Thank you, I tried to improve it once more. I cant create a reproducible example though, I have no idea how to create a dataset and such... sorry. – Manik Jan 17 '18 at 12:08
  • @drmariod It gives me a dataframe, but that dataframe gives NAs in Condition which doesn't make sense. – Manik Jan 17 '18 at 12:09
  • Your code works fine with an example dataframe, see `myResult <- ddply(mtcars, c("cyl", "gear"), summarise, N = length(mpg), mean = mean(mpg), sd = sd(mpg), se = sd / sqrt(N))` – zx8754 Jan 17 '18 at 12:22
  • You could provide something like `put(head(df))`. – drmariod Jan 17 '18 at 12:48
  • @zx8754 that works for me too, that is so weird... could it have anything to do with the classes? – Manik Jan 17 '18 at 12:54
  • @drmariod what do you mean by that? i tried that code but it doesnt know 'put', I cant find it in the help either – Manik Jan 17 '18 at 12:54
  • sorry, `dput`, (stupid auto correction) – drmariod Jan 17 '18 at 12:56
  • ok, this is the weirdest thing: I used your code @zx8754, exchanged every part with the names in my dataset and it worked. The weirdest thing: the upper creates an error, the lower doesnt. `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))` – Manik Jan 17 '18 at 13:01
  • Ok, this has worked and I am able to continue. As there was no real 'solution' in the sense of something one could make sense of, what do I do? Close the question? – Manik Jan 17 '18 at 13:16

0 Answers0