It's throwing an error because you're passing the newflip
to the function (which is a list). As per the boxcox
function's help (use ?boxcos
to access function's documentation), the output of the function is a list comprising of the following:
A list of class boxcox with elements:
x.t
transformed original data
x
original data
... (other elements in the list)
So if you pass newflip$x.t
to the hist
function it should work.
Below is a more complete (reproducible) answer:
library(palmerpenguins)
library(bestNormalize)
data(penguins)
ppp <- penguins
bestNormalize(ppp$flipper_length_mm)
ok <- orderNorm(ppp$flipper_length_mm)
# There's a base function with the same name; so best
# use :: specify the package
newflip <- bestNormalize::boxcox(ppp$flipper_length_mm)
newflip
hist(newflip$x.t)
BONUS MATERIAL
- In R use
<-
as the assignment operator. There's a subtle difference between <-
and =
. See this answer for details.
- While
hist()
function is ok for a quick glance, use ggplot2
for better graphs. See this document for details.