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" ... |
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 |
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 |
hist(as.numeric(x)) # Applying hist() & as.numeric() functions