r - Converting date column in data frame -


r version: 3.1.0

the following threads have been read: - format date column in data frame - convert data frame date column timeseries

and several other information topic without luck.

i need import data frame .csv file, , need index date column specified date column.

df <- read.csv(sti, header=true) df$date <- as.date(df$date, format="%y%m%d") 

(i've tried several other dateformats)

this should simple, result either column filled n/as, column wrong dates og error message.

my csv file contains excel date formats, , i've tried changing language settings in windows.

i know it's date format, not know what. dput() of head seems way off. here's shorted version:

structure(list(date = c("30/12/2013", "27/12/2013", "23/12/2013",  "20/12/2013", "19/12/2013", "18/12/2013"), maerska = c(11180,  11150, 10900, 10770, 10670, 10500), wdh = c(527, 522, 515.5,  515.5, 512, 504.5), vws = c(160.2, 159.8, 157, 156.6, 156.5,  153), tryg = c(524.5, 523, 520.5, 519, 504, 484), top = c(142.8,  142.5, 141.9, 141.5, 139.9, 136.5), tdc = c(52.6, 52.7, 52.45,  51.95, 51.65, 51.85), pandora = c(294, 301.2, 304, 300.3, 296.1,  293.1), novob = c(198.8, 197.2, 195.1, 196.3, 195.6, 190.7),      nordea = c(72.05, 71.35, 70.6, 70.1, 68.65, 67.8), colob = c(359,      358.3, 353.4, 353.2, 350.2, 342), chr = c(215.4, 215.7, 212.3,      209.1, 206.3, 204.2), carlb = c(600, 596, 586.5, 586, 584,      573), maerskb = c(11770, 11740, 11510, 11310, 11210, 11070     ), jyske = c(292.5, 288, 284.4, 282.8, 276.9, 275.7), gn = c(133.2,      132.3, 130.5, 129, 127.8, 126.2), genmab = c(212, 214.9,      217.4, 222.5, 221.6, 216.7), fls = c(296.1, 290.3, 280.3,      278.1, 273.6, 267.1), dsv = c(177.8, 178.2, 176.8, 174, 171.2,      169.3), danske = c(124.4, 124.3, 124.3, 123.7, 121, 120.3     ), novozymesb = c(228.9, 229.9, 228.5, 230.4, 219.9, 215.6     )), .names = c("date", "maerska", "wdh", "vws", "tryg", "top",  "tdc", "pandora", "novob", "nordea", "colob", "chr", "carlb",  "maerskb", "jyske", "gn", "genmab", "fls", "dsv", "danske", "novozymesb" ), row.names = c(na, 6l), class = "data.frame") 

additional information:

> sessioninfo() r version 3.1.0 (2014-04-10) platform: x86_64-w64-mingw32/x64 (64-bit)  locale: [1] lc_collate=english_united kingdom.1252  [2] lc_ctype=english_united kingdom.1252    [3] lc_monetary=english_united kingdom.1252 [4] lc_numeric=c                            [5] lc_time=english_united kingdom.1252      attached base packages: [1] stats     graphics  grdevices utils     datasets  methods   base  

i hope has idea might cause problem. later on need convert dataframe zoo object, since package performanceanalytics needs input.

using data posted above, date column character. , since dates "30/12/2013" format should "%d/%m/%y" not "%y%m%d". important format correct make conversion. therefore should able

df$date <- as.date(df$date, format="%d/%m/%y") 

with sample data,

> class(df$date)=="date" [1] true > sum(is.na(df$date))==0 [1] true 

so looks good.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -