[R] A Question about read.table and Data Frames in R

Robert Sherry rsherry8 at comcast.net
Mon Jun 30 00:22:17 CEST 2014


I created the following file:

symbol,shares
XOM,1000
APA,400
CVX,200

I then read the file in R using the command:
	stockList=read.table("/NotesOnR/stockList", header = T, sep=",")

I would then expect the following expression to evaluate to the simple
string APA:
	stockList$symbol[2]
However when I type that in on the command line, I get:
[1] APA
Levels: APA CVX XOM

I would also expect to be able to print out the table by using the command:
	for( i in 1:3 ) {
		print( stockList$symbol[i] )
		print ( stockList$shares[i] )
	}

However, as part of the output I get:
	Levels: APA CVX XOM
I do not understand what is going on. Also, when I try passing the
expression stockList$symbol to a standard function in R, it does not work.

I think that I am missing something here but I am not sure what I am
missing. Should I be writing code like:
	for  ( i in stockList$smybol )
However,  given the symbol, I am not sure how to get the share count that is
in the same row.

I thank the group in advance for their responses.

Bob



More information about the R-help mailing list