‘p_value’ is not a slot in class “data.frame”

I am trying to calculate chisq.test and print our residuals and p.value for each run

p_values <- numeric(nrow(df))
for (i in 1:nrow(df)) {
  table <- c(df$eu[i], df$hetero[i])
  result <- chisq.test(table)
  residuals[i] <- result$residuals
  p_values[i] <- result$p.value
  result$p.value
}
df$residuals <- residuals
df@p_value <- p_values

I receive this error:

Error in (function (cl, name, valueClass) :
‘p_value’ is not a slot in class “data.frame”

Column 1 Column 2
eu hetero
0.00010600 0.00002300
0.00009900 0.00001000
0.00010600 0.00000700
0.00009100 0.00001500
0.00011100 0.00000900
0.00008800 0.00003000
0.00010500 0.00004100
0.00009900 0.00000500
0.00010400 0.00000700

this symbol is for accessing slots, anologous to how $ can be used to access lists (of which data.frame are a particular example of)
why did you choose to write df@p_value <- p_values ?
does
df$p_value <- p_values do what you want ?

aaaakhhh, the whole thing was just a typo! :confused: thanks @nirgrahamuk

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.