tags:

views:

64

answers:

1

Hi,

I have a long list of dates that i want to parse, they are in a dataframe (the_dates). I've loaded them into R (from a sqlite db) just fine, however, if i do str(the_dates) i get:

'data.frame':   3968 obs. of  1 variable: 

somehow R treats this as a single variable, which is why i am having trouble converting into Date format - i found a workaround:

as.Date(the_dates[1:3968,], "%B %d, %Y")

This works, but is obviously not optimal because I have to lookup the length manually (length(the_dates) returns 1) -- any ideas what i am doing wrong?

Thanks!

+4  A: 

That's right. You have only "one variable" (i.e. column) in your data.frame. A column is a "variable" and a row is an "observation".

Try this:

as.Date(the_dates[,1], "%B %d, %Y")

The "length" of a data.frame comes from nrow, not length.

> df <- data.frame(a=1:20)
> str(df)
'data.frame':   20 obs. of  1 variable:
 $ a: int  1 2 3 4 5 6 7 8 9 10 ...
> length(df)
[1] 1
> nrow(df)
[1] 20

I recommend reading "An Introduction to R".

Shane
Aha - thanks Shane - worked a charm
flyingcrab