Closed mattansb closed 1 year ago
What does mutate()
on a data frame do, or what would you like to achieve?
I would like to be able to manipulate the ggeffects
data frame.
It seems like these break the printing method somehow.
m <- lm(mpg ~ factor(cyl), mtcars)
gge <- ggeffects::ggpredict(m, "cyl")
gge1 <- dplyr::mutate(gge)
print(gge1)
#> Error in colnames(x)[1] <- focal_term: replacement has length zero
gge2 <- gge[c(1:2, 4:6)]
print(gge2)
#> Error in colnames(x)[1] <- focal_term: replacement has length zero
Created on 2023-02-08 with reprex v2.0.2
Do you know more about [.class
generics?
I do not :(
library(ggeffects)
m <- lm(mpg ~ gear * factor(cyl), mtcars)
gge <- ggeffects::ggpredict(m, c("gear", "cyl"))
gge
#> # Predicted values of mpg
#>
#> # cyl = 4
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 3 | 23.57 | [18.82, 28.33]
#> 4 | 26.41 | [24.35, 28.46]
#> 5 | 29.24 | [25.12, 33.35]
#>
#> # cyl = 6
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 3 | 19.76 | [15.51, 24.01]
#> 4 | 19.74 | [17.14, 22.34]
#> 5 | 19.72 | [14.52, 24.92]
#>
#> # cyl = 8
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 3 | 15.05 | [13.11, 16.99]
#> 4 | 15.22 | [12.66, 17.79]
#> 5 | 15.40 | [10.65, 20.15]
gge[c(1:2, 4:6)]
#> # Predicted values of mpg
#>
#> # cyl = 4
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 3 | 23.57 | [18.82, 28.33]
#> 4 | 26.41 | [24.35, 28.46]
#>
#> # cyl = 6
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 3 | 19.76 | [15.51, 24.01]
#> 4 | 19.74 | [17.14, 22.34]
#>
#> # cyl = 8
#>
#> gear | Predicted | 95% CI
#> ---------------------------------
#> 4 | 15.22 | [12.66, 17.79]
m <- lm(mpg ~ factor(cyl), mtcars)
gge <- ggeffects::ggpredict(m, "cyl")
gge
#> # Predicted values of mpg
#>
#> cyl | Predicted | 95% CI
#> --------------------------------
#> 4 | 26.66 | [24.68, 28.65]
#> 6 | 19.74 | [17.25, 22.23]
#> 8 | 15.10 | [13.34, 16.86]
gge[c(1:2)]
#> # Predicted values of mpg
#>
#> cyl | Predicted | 95% CI
#> --------------------------------
#> 4 | 26.66 | [24.68, 28.65]
#> 6 | 19.74 | [17.25, 22.23]
Created on 2023-04-26 with reprex v2.0.2
Can you check if this works with mutate()
now?
Great! Thanks!
(This use to work)
Created on 2023-02-07 with reprex v2.0.2
See here for why this isn't actually related to dplyr, which is why I'm posting here.