Fixing R Error in hist.default – x must be numeric (2 Examples)

In this tutorial, I’ll show how to avoid the error in hist.default : ‘x’ must be numeric in the R programming language.

Creation of Example Data

set.seed(9648765)                    # Set seed
x <- as.character(rnorm(5000), 2)    # Example data
x                                    # Showing some values of example data
# [1] "-0.539007245990738"   "-0.379583127859177"   "0.259512920568062"    "-1.74503840241083" ...

Example 1: Replicating the Error Message in hist.default(X) : ‘x’ must be numeric

hist(x)                              # hist() function leads to error
# Error in hist.default(x) : 'x' must be numeric

Example 2: Solving the Error Message in hist.default(X) : ‘x’ must be numeric

hist(as.numeric(x))                  # Applying hist() & as.numeric() functions

r graph figure 1 fixing r error hist default x must be numeric

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top