Re: [R] extracting numerical data from text field

From: Gabor Grothendieck <ggrothendieck_at_myway.com>
Date: Thu 24 Mar 2005 - 15:04:41 EST

Luis Tercero <luis.tercero <at> ebi-wasser.uni-karlsruhe.de> writes:

:
: I have imported a data frame that looks like this:
:
: Measurement.Date.and.Time Z.Average..nm. PDI
: 572 Dienstag, 22. März 2005 11:05:59 366,4 0,468
: 573 Dienstag, 22. März 2005 11:09:30 353,4 0,532
: 574 Dienstag, 22. März 2005 11:12:59 343 0,428
: 575 Dienstag, 22. März 2005 11:16:28 354,1 0,433
: 576 Dienstag, 22. März 2005 11:19:59 341,9 0,349
: 577 Dienstag, 22. März 2005 11:23:29 334,9 0,429
: ...
:
: Would there be a way to extract the time in numerical form from the
: Measurement.Date.and.Time field? What I would like to do is a time
: series where, for example,
: Dienstag, 22. März 2005 11:05:59 is time=0 min
: Dienstag, 22. März 2005 11:09:30 is time=3.5 min, etc.
:
: Thank you in advance for your help.
:
: Luis

Make sure that you are in a German locale:

  # this works on Windows XP. On other OS, "ge" code may differ.   Sys.setlocale("LC_TIME", "ge")

Then if DF is your data frame use strptime (see ?strptime for more on the % codes):

  dat <- strptime(DF[,1], "%A, %d. %B %Y %H:%M:%S")   dat - dat[1] # difference in time since the first date time



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Mar 24 15:10:56 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:55 EST