Trying to Make a histogram with this data but R is not letting me

Screen Shot 2022-10-06 at 7.49.10 PM

IM trying to make a histogram wherein weight is in the horizontal axis
I cant do histogram.
I cant use command

variable=data$Weight.Count
and hist (variable, frequency=F)

Ive tried changing weight to number, no success

class(count)
[1] "character"
count=as.numeric(gsub(",","",count))
class(count)
[1] "numeric"
variable=weight.count
Error: object 'weight.count' not found
variable=data$weight.count
variable=data$weight.count
hist(variable)
Error in hist.default(variable) : 'x' must be numeric
class(weight)
[1] "character"
weight=as.numeric(gsub(",","",weight))
Warning message:
NAs introduced by coercion
class(weight)
[1] "numeric"
variable=weight.count
Error: object 'weight.count' not found
variable=data$weight.count
variable=data$weight.count
hist(variable)
Error in hist.default(variable) : 'x' must be numeric

That doesn't exist. You have two columns, weight and count.

You can't really make a histogram with the dataset that you have shown, unless this is just a summary of the dataset. You might want to make a bar plot instead.

I agree it should be a barplot but the book says a histogram and even a relative frequency histogram T_T. Is there any other around this.

Is there other data that you can make a histogram from?

A histogram is a bar chart. When your dataset has observations allocated to buckets suitable for an x axis and frequency counts for a yaxis, if you directly bar plot that the result is a histogram. Your count field is character , its a set of digit symbols with commas. The easiest way to convert such a field is with library readr which has a parse_number function.

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