[R] extracting numerical data from text field

Gabor Grothendieck ggrothendieck at myway.com
Thu Mar 24 05:04:41 CET 2005


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




More information about the R-help mailing list