[R] conversion of string

Jim Lemon jim at bitwrit.com.au
Mon Jan 23 11:55:27 CET 2012


On 01/23/2012 07:35 PM, uday wrote:
> I new in R programming language.
>
> I have some time data
>
> time
>   [1] "2005-01-03 05:11:39 UTC" "2005-01-03 06:36:02 UTC" "2005-01-03
> 06:36:55 UTC"
>   [4] "2005-01-03 06:37:00 UTC" "2005-01-03 06:38:04 UTC" "2005-01-03
> 06:38:04 UTC"
>   [7] "2005-01-03 06:38:04 UTC" "2005-01-03 06:38:04 UTC" "2005-01-03
> 06:38:05 UTC"
> [10] "2005-01-03 06:38:05 UTC" "2005-01-03 06:38:05 UTC" "2005-01-03
> 06:38:05 UTC"
>
> from this data set I would like to separate Year Month Day Hour Minute
> Second
>
> could you please tell which command can separate this data to the format
> which I needed?
>
Hi uday,
If I read your message correctly, you don't have to convert the strings 
to dates. Try this:

timebits<-list()
timeseps<-c("-",":")
for(i in 1:2) {
  for(j in 1:3)
   timebits[[3*(i-1)+j]]<-sapply(strsplit(sapply(strsplit(
    timestrings," "),"[",i),timeseps[i]),"[",j)
}
names(timebits)<-
  c("Year","Month","Day","Hour","Minute","Second")
timebits

Jim



More information about the R-help mailing list