Frage

I have been sent many datasets with the date in the following format:

10.18.12 klo 04.00.00 ap.
10.18.12 klo 04.00.00 ip.

The dates are in Finnish. 'klo' is for time, ap. is for 'am' and ip. is for 'pm'. I am trying to read it with strptime but I can't see how to deal with unwanted characters like "klo", nor how I can tell strptime that what ap and ip stand for. I thought that something like this might work

time = strptime(paste(date),format='%m.%d.%y%n%n%n%n%n%I.%M%S%n%p%n')

because I thought that I could define unwanted characters as white space but it doesn't work. Any advice?

Thanks.

War es hilfreich?

Lösung

Here you go

dt = "10.18.12 klo 04.00.00 ap."
strptime(gsub(' ip.',' PM',gsub(' ap.',' AM',gsub(' klo ',':',dt))),format='%m.%d.%y:%I.%M.%S %p')
[1] "2012-10-18 04:00:00"

dt = "10.18.12 klo 04.00.00 ip."
strptime(gsub(' ip.',' PM',gsub(' ap.',' AM',gsub(' klo ',':',dt))),format='%m.%d.%y:%I.%M.%S %p')
[1] "2012-10-18 16:00:00"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top