【发布时间】:2022-08-03 04:59:32
【问题描述】:
根据下面的代码和数据,如何避免separate 函数删除原始列(GEOID)?
代码+数据(df):
library(tidyverse)
# Sample data
df = structure(list(GEO_ID = c(\"1500000US120110101021\", \"1500000US120110101022\",
\"1500000US120110101031\", \"1500000US120110101032\", \"1500000US120110101033\",
\"1500000US120110101041\"), GEO_ID_REV = c(1.2e+11, 1.2e+11, 1.2e+11,
1.2e+11, 1.2e+11, 1.2e+11)), row.names = c(NA, -6L), class = c(\"tbl_df\",
\"tbl\", \"data.frame\"))
# Split GEO_ID into two new columns and keep the existing column as well.
df = df %>% separate(GEO_ID, c(\"GeoID\", \"US\"), \"US\") # Drops the existing GEO_ID column