0

I am thinking how you can dynamically change the time duration form (etc 11h11 resembling %Hh%M) to minute form like %M. I think it is best to maintain the original data form used by EMFIT-QS device. Data

Name,Time_duration
Leo,11h11

Code

DF <- read.csv("/home/masi/Documents/Data/data.csv", header = T, sep = ",")
str(DF)

Outut

$ Time_duration         : Factor w/ 1 level 11h11",..

My proposal

  1. Change data time duration to minutes where second column for specifying units to avoid confusion because non-standard units

    Name,Time_duration
    -, min
    Leo,671
    
  2. Do not change the standard fields given by %Hh%M, I would really like to programmatically convert all fields manually to minute presentation %M

R: 3.3.3

2
  • Can you preprocess with another language, or does it all need to be in R ? Commented May 6, 2017 at 17:18
  • @ivanivan Answer can be about another language. It can help to see the other side of the problem here. Commented May 6, 2017 at 18:17

1 Answer 1

1

You could use a custom colClasses function - as described in Specify custom Date format for colClasses argument in read.table/read.csv

To illustrate; given

$ cat file.csv 
Name,Time_duration
Leo,11h11

then in R

> setClass('myTime')
> 
> setAs('character','myTime', function(from) {
+ x <- as.POSIXlt(from, format='%Hh%M')
+ return (x$hour*60 + x$min)
+ })
> 
> data <- read.csv2(file='file.csv', sep=',', dec='.', header=TRUE, 
+ colClasses=c('character','myTime'))
> 
> data
  Name Time_duration
1  Leo           671
> 
1
  • Confirmed, this approach works! Commented May 7, 2017 at 15:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.