I have a CSV file which contains two format(General and Date) for Date Column. Having issue in while working with R -
> df<-read.csv("weatherdatatrail.csv") > header=t > df$date [1] 01-01-1989 01-02-1989 01-03-1989 01-04-1989 01-05-1989 01-06-1989 [7] 01-07-1989 01-08-1989 01-09-1989 01-10-1989 01-11-1989 01-12-1989 [13] 1/13/1989 1/14/1989 1/15/1989 1/16/1989 1/17/1989 1/18/1989 [19] 1/19/1989 1/20/1989 1/21/1989 1/22/1989 1/23/1989 1/24/1989 [25] 1/25/1989 1/26/1989 1/27/1989 1/28/1989 1/29/1989 1/30/1989 [31] 1/31/1989 31 levels: 01-01-1989 01-02-1989 01-03-1989 01-04-1989 ... 1/31/1989
while performing r below code, works general format date format showing na..
> df$date<-as.date(as.character(df$date),format="%m/%d/%y") > str(df) 'data.frame': 31 obs. of 10 variables: $ date : date, format: na na ... $ longitude : num 77.2 77.2 77.2 77.2 77.2 ... $ latitude : num 11.4 11.4 11.4 11.4 11.4 ... $ elevation : int 282 282 282 282 282 282 282 282 282 282 ... $ max.temperature : num 28.2 28.5 29.6 29.3 27.9 ... $ min.temperature : num 10.9 15.4 14.2 16.5 16.3 ... $ precipitation : num 0 0.0378 0.0893 0.2077 0.1785 ... $ wind : num 2.17 2.1 2.03 2.05 2.09 ... $ relative.humidity: num 0.559 0.705 0.718 0.779 0.781 ... $ solar : num 21 20.5 19.3 19.2 14.8 ... > df$date [1] na na na na na [6] na na na na na [11] na na "1989-01-13" "1989-01-14" "1989-01-15" [16] "1989-01-16" "1989-01-17" "1989-01-18" "1989-01-19" "1989-01-20" [21] "1989-01-21" "1989-01-22" "1989-01-23" "1989-01-24" "1989-01-25" [26] "1989-01-26" "1989-01-27" "1989-01-28" "1989-01-29" "1989-01-30" [31] "1989-01-31"
i unable pull perfect result.. please me out
you use library(lubridate)
(as commented @mrflick)
library(lubridate) as.date(mdy(v1)) #[1] "1989-01-01" "1989-01-02" "1989-01-15"
data
v1 <- c("01-01-1989", "01-02-1989", "1/15/1989")
Comments
Post a Comment