0

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!

2
  • 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. Commented Feb 8, 2016 at 4:42
  • 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. Commented Feb 8, 2016 at 8:14

1 Answer 1

1

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.