'x' and 'p' must have the same number of elements even though data frames have the same length

91 Views Asked by At

I'm running into an issue with my chisq.test() function where I'm passing in the data frames of each parameter (the p parameter is also decimals that add to one), but I am pulling my hair out trying to figure out this problem. Even though they are data frames of the same length, with the same amount of observations, I am getting flagged for these issues over and over again.

# chisq.test(x = observed, p = expected/126) 
# the expected are in probabilities rather than counts

df <- matrix(observed_values)
df2 <- matrix(expected_values)

chisq.test(x = double(df), p = double(df2))


I have tried to divided all my elements in df2 by 126 (the sample size), changed the data frame to have three variables with one observation, and I have looked on here.

Here is the error message:

0

There are 0 best solutions below