I have a text (csv) file) with two columns: dates and numeric measurements.
I read it using read.table and the dates get read as a factor, with as many
levels as there are dates in the data.  How can I create a matrix-like data
structure (data frame?) which has one column of “real” dates (a vector of
dates, not a factor variable) and one column of the numeric measurements?
The strptime function converts the data into dates, but the naïve

 

foo <- read.table(…)                               # foo is a 2-column data
frame with the first column a factor (of dates) and the second column a
return vector

foo.dates <- strptime(fool[,1], format)       

cbind(foo.dates, foo[,2]) 

 

does not work (because foo.dates is not a vector) and produces a wrong
dimension error:

 

Warning message:

In cbind(foo.dates, foo[,2]) :

  number of rows of result is not a multiple of vector length (arg 1)

 

I am sure this is a very basic question on types, but I have spent hours on
this without much luck.  Any ideas/suggestions would be greatly welcome.

 

Thank you in advance.

 

 

Achilles Venetoulias
Tel: (212) 988-2276
axill...@stanfordalumni.org

 


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to