Michael Minkoff
Michael Minkoff

Reputation: 131

'x' must be numeric ERROR in R while trying to create a Leaf and Stem display

I am a beginner at R and I'm just trying to read a text file that contains values and create a stem display, but I keep getting an error. Here is my code:

setwd("C:/Users/Michael/Desktop/ch1-ch9 data/CH01")
gravity=read.table("C:ex01-11.txt", header=T)
stem(gravity)
    **Error in stem(gravity) : 'x' must be numeric**

The File contains this:

'spec_gravity' 0.31 0.35 0.36 0.36 0.37 0.38 0.4 0.4 0.4 0.41 0.41 0.42 0.42 0.42 0.42 0.42 0.43 0.44 0.45 0.46 0.46 0.47 0.48 0.48 0.48 0.51 0.54 0.54 0.55 0.58 0.62 0.66 0.66 0.67 0.68 0.75

If you can help, I would appreciate it! Thanks!

Upvotes: 0

Views: 1002

Answers (1)

csgillespie
csgillespie

Reputation: 60492

gravity is a data frame. stem expects a vector. You need to select a column of your data set and pass to stem, i.e.

## The first column
stem(gravity[,1])

Upvotes: 1

Related Questions