2012-09-27 28 views
1

分割一列與空間我有一個數據幀,其第一20個OBS是這樣的:在之間中的R

 userID      appName   startTime    endTime endResult Handset Gender Age Telecom 
1 007qkrtk    com.kakao.talk 2012-07-28 00:58:05 2012-07-28 00:59:17   2 Others Female 20-29  KT 
2 007qkrtk    com.kakao.talk 2012-07-19 16:09:16 2012-07-19 16:09:30   2 Others Female 20-29  KT 
3 007qkrtk   com.facebook.katana 2012-07-03 14:16:25 2012-07-03 14:16:55   1 Others Female 20-29  KT 
4 007qkrtk cn.jingling.motu.photowonder 2012-07-29 17:10:18 2012-07-29 17:11:15   3 Others Female 20-29  KT 
5 007qkrtk   com.android.browser 2012-07-14 16:09:09 2012-07-14 16:10:59   1 Others Female 20-29  KT 
6 007qkrtk    com.htc.album 2012-07-13 15:41:36 2012-07-13 15:41:56   1 Others Female 20-29  KT 
7 007qkrtk    com.kakao.talk 2012-07-28 12:46:15 2012-07-28 12:46:23   3 Others Female 20-29  KT 
8 007qkrtk    com.android.mms 2012-07-29 14:23:42 2012-07-29 14:23:45   2 Others Female 20-29  KT 
9 007qkrtk    com.htc.launcher 2012-07-14 15:21:31 2012-07-14 15:21:34   2 Others Female 20-29  KT 
10 007qkrtk    com.kakao.talk 2012-07-09 20:36:45 2012-07-09 20:37:14   3 Others Female 20-29  KT 
11 007qkrtk    com.kakao.talk 2012-07-05 07:44:44 2012-07-05 07:45:18   2 Others Female 20-29  KT 
12 007qkrtk   com.facebook.katana 2012-07-23 14:47:51 2012-07-23 14:49:21   1 Others Female 20-29  KT 
13 007qkrtk      my.Frank 2012-07-09 13:14:40 2012-07-09 13:15:11   3 Others Female 20-29  KT 
14 007qkrtk   com.facebook.katana 2012-07-17 17:10:08 2012-07-17 17:10:37   2 Others Female 20-29  KT 
15 007qkrtk   com.facebook.katana 2012-07-20 14:36:08 2012-07-20 14:36:38   1 Others Female 20-29  KT 
16 007qkrtk    com.kakao.talk 2012-07-11 09:31:28 2012-07-11 09:32:16   2 Others Female 20-29  KT 
17 007qkrtk    com.show.mini 2012-07-09 16:55:30 2012-07-09 16:56:53   2 Others Female 20-29  KT 
18 007qkrtk    com.kakao.talk 2012-07-11 08:36:34 2012-07-11 08:37:35   2 Others Female 20-29  KT 
19 007qkrtk   com.facebook.katana 2012-07-12 17:27:11 2012-07-12 17:28:37   2 Others Female 20-29  KT 
20 007qkrtk   com.android.phone 2012-07-27 14:47:32 2012-07-27 14:48:38   2 Others Female 20-29  KT 

於starttime和endTime具有日期和時間分量通過空間一起分離。從兩列我需要分開日期和時間,並將其中一個保存在startTime和endTime的新列中。

回答

2

使用strftime的時間戳處理,以你的願望,如:

strftime("2012-07-28 00:58:05","%Y-%m-%d") 
[1] "2012-07-28" 
strftime("2012-07-28 00:58:05","%H:%M:%S") 
[1] "00:58:05" 

它矢量化,所以你可以使用:

dfr$start.date <- strftime(dfr$startTime,"%Y-%m-%d") 
dfr$start.time <- strftime(dfr$startTime,"%H:%M:%S")