[R] How can I correctly access a string element of a dataframe?
miaojpm at gmail.com
Thu Jul 26 16:53:39 CEST 2012
I would like to read the data file via read.csv (the 3rd line of the
following program) and the file name is stored in a dataframe. Since I have
several files to read, I store the file names as well as the sample period
inside a file “B_M2Q.csv” and I read the file name first, and then read the
The content of the file "B_M2Q.csv" is
(The file is attached to this email)
The three-line program is as follows:
m2q<-read.csv(file="B_M2Q.csv", header=FALSE) # Read the file containing
file names and sampling periods of numerical data
m2qdf<-as.data.frame(m2q) #Make the file of filenames a dataframe
x1<-read.csv(file=m2qdf[1,2]) # Read the numerical data
Nevertheless, there is an error when I attempt to read the numerical data
Error in read.table(file = file, header = header, sep = sep, quote = quote,
'file' must be a character string or connection
It is a problem of the file name , since I can read the data smoothly if I
change the line to
Could someone tell me what the problem is?
How can modify the orignal program so that I can store the sampling periods
and filenames in a dataframe, and then I read it?
How can I correctly access a string element of a dataframe?
More information about the R-help