【发布时间】:2017-05-10 16:42:06
【问题描述】:
我有这个数据框
CC.Number Date Time Accident.Type Location.1
1 12T008826 07/01/2012 1630 PD (39.26699, -76.560642)
2 12L005385 2012 年 7 月 2 日 1229 PD(39.000549,-76.399312)
3 12L005388 07/02/2012 1229 PD (39.00058, -76.399267)
4 12T008851 07/02/2012 445 PI (39.26367, -76.56648)
5 12T008858 07/02/2012 802 PD (39.240862, -76.599017)
6 12T008860 07/02/2012 832 PD (39.27022, -76.63926)
我想将 Location.1 列拆分为 "alt" 和 "lng" 列,就像
CC.Number Date Time Accident.Type alt lng
1 12T008826 07/01/2012 1630 PD 39.26699 -76.560642
2 12L005385 07/02/2012 1229 PD 39.000549 -76.399312
3 12L005388 07/02/2012 1229 PD 39.00058 -76.399267
我试过了
location <- md$Location.1
location1 <- substring(location, 2)
location2 <- substr(location1, 1, nchar(location1)-1 )
location3 <- strsplit(location2, ",")
但停留在将 location3 从列表转换为数据框
我试过了
ocdf<-data.frame(location2)
colnames(locdf)[1] = c("x")
df <- separate(location, col=x,into = c("lat","log"), sep = ",")
但我得到一个错误
UseMethod("separate_") 中的错误:没有适用的方法 'separate_' 应用于“字符”类的对象
【问题讨论】: