I have a csv file with the content like below:
VA1,VA2,2014-05-24,,2014-05-22 15:50:16
VA2,VA1,2014-05-24,2014-05-26,2014-05-22 15:50:16
How can I read it? Standard read.csv
can not recognize dates YYYY-MM-DD. I've tried to use read.zoo
, but I am not sure how to:
Here is what I've tried:
library(zoo)
colClasses <- c("factor", "factor", "Date", "Date", "Date")
fmt <- "%Y-%m-%d"
z <- read.zoo("file.csv", header = FALSE, sep = ",", quote = "", format = fmt, tz = "", colClasses = colClasses)
You can't use read.zoo
to read that sort of data. Its meant for time series. Try the following. No packages needed. The code below has been written to be self contained but the text = Lines
part could be replaced with the filename, e.g. read.table("myfile.dat", ...whatever...)
:
Lines <- "VA1,VA2,2014-05-24,,2014-05-22 15:50:16
VA2,VA1,2014-05-24,2014-05-26,2014-05-22 15:50:16"
DF <- read.table(text = Lines, sep = ",", as.is = TRUE, na.strings = "")
transform(DF, V3 = as.Date(V3), V4 = as.Date(V4), V5 = as.POSIXct(V5))
giving:
V1 V2 V3 V4 V5
1 VA1 VA2 2014-05-24 <NA> 2014-05-22 15:50:16
2 VA2 VA1 2014-05-24 2014-05-26 2014-05-22 15:50:16
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다