Error in hist.default(): 'x' must be numeric

This is the R Commands that I wrote :

ecommerce_data.df <- read.csv("https://goo.gl/hzRyFd")

with(subset(ecommerce_data.df,
profile %in% c("Parent", "Teacher")
& productKnewWhatWanted %in% c("No", "Yes")),
hist(~ ecommerce_data.df$productKnewWhatWanted | ecommerce_data.df$profile))

but sadly, when I execute them, I have this error:

Error in hist.default(~ecommerce_data.df$productKnewWhatWanted | ecommerce_data.df$profile) :
'x' must be numeric

And I don't know how to do it since no as.numeric() or packages have helped me.

Thank you for the help !

The hist() function does not take a formula starting with ~, it takes a numeric vector. If you want a histogram of the TRUE and FALSE values returned by ecommerce_data.df$productKnewWhatWanted | ecommerce_data.df$profile), then use

hist(as.numeric(ecommerce_data.df$productKnewWhatWanted | ecommerce_data.df$profile))

This topic was automatically closed 21 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.