0

I was wondering why summarise() is returning a table, while I was expecting a row? Here's the code:

car %>% group_by() %>%
  mutate(grandmean = mean(Puntuacion, na.rm = TRUE)) %>%
  mutate(SST1 =  sum ((Puntuacion - grandmean)^2)) %>%
  group_by(Tipo_vehiculo) %>%
  mutate(groupmean = mean(Puntuacion, na.rm = TRUE)) %>%
  mutate(vec_sum = ((Puntuacion - groupmean)^2)) %>%
  group_by() %>%
  mutate(SSW1 = sum(vec_sum)) %>%
  mutate(SSB1 = SST1 - SSW1) %>%
  summarise(SST2 = SST1, SSB2 = SSB1, SSW2 = SSW1, F = (SSB1 / (m-1)) / (SSW1/ (n-m)))

Thanks for your help!

** even though Im still not sure how to properly solve it, i solved it adding:

%>% summarise(SST = SST2[1], SSB = SSB2[1], SSW = SSW2[1], F_value = F[1])
Riki LC
  • 15
  • 4
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. I'm not sure why you were epexting a row. You aren't doing any operations in your `summarize()` that would collapse a column of values down to a single value – MrFlick Jan 22 '21 at 19:42
  • yeah, i thought that was the problem too, but i am not sure how to solve it. I got the expected results with mutate, but with a vector equal to the rows of my dataframe, and thats what summarise its returning. – Riki LC Jan 22 '21 at 19:46
  • Well, we can't see at all what you are getting without a reproducible example so it's not clear what you want exactly. – MrFlick Jan 22 '21 at 19:52

0 Answers0