Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cut a datetime and remain the time part only

Tags:

r

I have data like below:

2018-04-01 00:12:45.823 
2018-04-01 00:12:49.897 
2018-04-01 00:12:56.207

How to cut them only remain:

00:12:45.823
00:12:49.897
00:12:56.207
like image 651
Jane Avatar asked Dec 13 '22 12:12

Jane


1 Answers

We can also use and convert back to time:

mytime<-"2018-04-01 00:12:45.823"
strsplit(mytime," ")[[1]][2]
#[1] "00:12:45.823"

Well, reading this data with read.table breaks it up "nicely":

mytime<-read.table(text="2018-04-01 00:12:45.823 
2018-04-01 00:12:49.897 
                   2018-04-01 00:12:56.207",header=F)
      V1           V2
1 2018-04-01 00:12:45.823
2 2018-04-01 00:12:49.897
3 2018-04-01 00:12:56.207
like image 87
NelsonGon Avatar answered Dec 28 '22 18:12

NelsonGon