0
votes

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!

1
Study the problem from the perspective of the class or mode of gravity. Dataframes are not of mode numeric. They are lists. You need to access a dataframe column ... which should be described in any introductory text.IRTFM
There may be a typo in your read.table unless you copied and pasted it here incorrectly. One would have expected read.table("C:/path/to/your/file/ex01-11.txt", header=T) instead of a filename with a ":" in it. It's possible that gravity is empty.David

1 Answers

1
votes

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])