0

I am trying to use pipe to filter and calculate Cohen's d statistic, but for some reason R will not recognise the column. I've tried this so many ways and can't get it to run..

df2 %>% filter(`Spreadsheet Row` == "Self-driving cars", `Zone Name` != "slider") %>% cohen.d(., Question,alpha=.05, data = Response)

Throws error: Error in cohen.d(., Question, alpha = 0.05, data = Response) : object 'Question' not found

This is the dataframe:

> df2 %>% filter(`Spreadsheet Row` == "Self-driving cars", `Zone Name` != "slider")
# A tibble: 96 x 6
   `Event Index`     PID `Spreadsheet Row` Question  `Zone Name` Response
   <chr>           <dbl> <fct>             <ord>     <chr>          <dbl>
 1 17            3799252 Self-driving cars Pre-stim  core_belief        3
 2 18            3799252 Self-driving cars Pre-stim  right_wrong        2
 3 19            3799252 Self-driving cars Pre-stim  moral_issue        4
 4 20            3799252 Self-driving cars Pre-stim  just_know          3
 5 25            3799252 Self-driving cars Post-stim core_belief        4
 6 26            3799252 Self-driving cars Post-stim right_wrong        5
 7 27            3799252 Self-driving cars Post-stim moral_issue        3
 8 28            3799252 Self-driving cars Post-stim just_know          4
 9 65            3799288 Self-driving cars Pre-stim  core_belief        4
10 66            3799288 Self-driving cars Pre-stim  right_wrong        4

And it is clearly recognised if I use SELECT:

df2 %>% filter(`Spreadsheet Row` == "Self-driving cars", `Zone Name` != "slider") %>% select(Question)
# A tibble: 96 x 1
   Question 
   <ord>    
 1 Pre-stim 
 2 Pre-stim 
 3 Pre-stim 
 4 Pre-stim 
 5 Post-stim
 6 Post-stim
 7 Post-stim
 8 Post-stim
 9 Pre-stim 
10 Pre-stim 
# ... with 86 more rows

But as soon as I try and use the column in any way it throws the object not found error. Driving me nuts!

dput(head(df2))
structure(list(`Event Index` = c(2, 3, 4, 5, 6, 11), PID = c(3800586, 
3800586, 3800586, 3800586, 3800586, 3800586), `Spreadsheet Row` = structure(c(4L, 
4L, 4L, 4L, 4L, 4L), .Label = c("E-waste", "Meat", "Plastic", 
"Self-driving cars"), class = "factor"), Question = c("Familiarisation", 
"Pre-stim", "Pre-stim", "Pre-stim", "Pre-stim", "Post-stim"), 
    `Zone Name` = c("slider", "core_belief", "right_wrong", "moral_issue", 
    "just_know", "core_belief"), Response = c(6, 5, 4, 5, 3, 
    7)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
), problems = structure(list(row = c(1543L, 1543L), col = c("Event Index", 
NA), expected = c("a double", "62 columns"), actual = c("END OF FILE", 
"1 columns"), file = c("'data_exp_44331-v24_task-4xn8.csv'", 
"'data_exp_44331-v24_task-4xn8.csv'")), row.names = c(NA, -2L
), class = c("tbl_df", "tbl", "data.frame")))

Using the rstatix package version works fine;

df2 %>% filter(`Spreadsheet Row` == "Self-driving cars", `Zone Name` != "slider") %>% rstatix::cohens_d(., Response ~ Question)
3
  • Which package are you using for cohen.d? effsize or psych or other? And you have data = response - what is Response? And can you use dput(head(df2)) to share a sample of your data?
    – Ben
    May 12, 2021 at 16:26
  • try ... %>% cohen.d("Question", ...)
    – Onyambu
    May 12, 2021 at 18:22
  • Hi there - the quotations marks don't work, but running cohens_d from rstatix package fixed it. Maybe the psych package version isn't pipe-able? For what it's worth I've put the dput(head) output above
    – Tzen
    May 14, 2021 at 9:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.