I have station wise Discharge data frame df
. The dates (I imported it from an existing .csv
file) format are irregular. Below is an example data frame:
> df
Station Date Discharge
1 A 1981-01-01 0.1
2 A 1981-02-01 0.0
3 B 1981-03-01 0.0
4 B 1981-04-01 0.0
5 B 1/13/1981 0.4
6 C 1/14/1981 0.2
7 D 1/15/1981 0.6
8 D 1981-16-01 0.1
9 D 1981-17-01 0.5
Because of this further processing of this data is difficult. I tried the following:
> df$Date <- as.Date(df$Date, "%m/%d/%Y")
> df
Station Date Discharge
1 A 1981-01-01 0.1
2 A 1981-02-01 0.0
3 B 1981-03-01 0.0
4 B 1981-04-01 0.0
5 B NA 0.4
6 C NA 0.2
7 D NA 0.6
8 D 1981-16-01 0.1
9 D 1981-17-01 0.5
NA's are being introduced. How to make the format of all the dates same. It would be nice to have date as d-m-y
format. Any guidance is appreciated. Thanks.