[R] converting character matrix to POSIXct matrix
Rui Barradas
ruipbarradas at sapo.pt
Fri Apr 26 23:24:54 CEST 2013
Hello,
You should keep this on the list, the odds of getting more and better
answers are greater.
I don't know if the following is what you want.
apply(time.m, 2, function(tt) as.POSIXct(tt, format = "%H:%M:%OS"))
Hope this helps,
Rui Barradas
Em 26-04-2013 21:49, hh wt escreveu:
> sapply doesn't do it. It just spits out the guts,
>
> $`08:00:20.799.sec`
> [1] 20.799
>
> $`08:00:20.799.min`
> [1] 0
>
> $`08:00:20.799.hour`
> [1] 8
>
> $`08:00:20.799.mday`
> [1] 26
>
> $`08:00:20.799.mon`
> [1] 3
>
> $`08:00:20.799.year`
> [1] 113
>
>
> On Fri, Apr 26, 2013 at 11:25 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
>
>> Hello,
>>
>> Use sapply instead.
>>
>>
>> Hope this helps,
>>
>> Rui Barradas
>>
>> Em 26-04-2013 18:51, hh wt escreveu:
>>
>>> I thought this is a common question but rseek/google searches don't yield
>>> any relevant hit.
>>>
>>> I have a matrix of character strings, which are time stamps,
>>>
>>> time.m[1:5,1:5]
>>>>
>>> [,1] [,2] [,3] [,4] [,5]
>>>
>>> [1,] "08:00:20.799" "08:00:20.799" "08:00:20.799" "08:00:20.799"
>>> "08:00:20.799"
>>> [2,] "08:00:21.996" "08:00:22.071" "08:00:23.821" "08:00:24.370"
>>> "08:00:25.573"
>>> [3,] "08:00:29.200" "08:00:29.200" "08:00:29.591" "08:00:30.368"
>>> "08:00:30.536"
>>> [4,] "08:00:31.073" "08:00:31.372" "08:00:31.384" "08:00:31.403"
>>> "08:00:31.867"
>>> [5,] "08:00:31.867" "08:00:31.867" "08:00:31.971" "08:00:34.571"
>>> "08:00:34.571"
>>>
>>> And i would like to convert it to a POSIXct matrix. I tried this,
>>>
>>> time1 = lapply(time.m, function(tt)strptime(tt, "%H:%M:%OS"))
>>>
>>> but it yields a list.
>>>
>>> Any tip is appreciated.
>>>
>>>
>>> Horace
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________**________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>
More information about the R-help
mailing list