我已经在R中切片以分隔文本和列,但在切片内部时遇到问题。我们说我有这个数据
Zip Code <- c("90042 34.11332407100048 -118.19142869099971",
"90040 33.99649121800047 -118.15148940099971",
"90007 34.02833141800045 -118.28507659499968")
我想只提取邮政编码并将其放在不同的列中。 long / lat也需要转到另一列。
我是否使用grep
?
答案 0 :(得分:0)
我们可以使用tidyverse
library(tidyverse)
separate(dat, ZipCode, into = c('value', 'lat', 'lon'), sep= ' ')
# A tibble: 3 x 3
# value lat lon
#* <chr> <chr> <chr>
#1 90042 34.11332407100048 -118.19142869099971
#2 90040 33.99649121800047 -118.15148940099971
#3 90007 34.02833141800045 -118.28507659499968
dat <- structure(list(ZipCode = c("90042 34.11332407100048 -118.19142869099971",
"90040 33.99649121800047 -118.15148940099971", "90007 34.02833141800045 -118.28507659499968"
)), .Names = "ZipCode", class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -3L))