1

我有一个数据框,其前 20 个 obs 是这样的:

     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。

4

1 回答 1

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")
于 2012-09-27T13:32:43.987 回答