tidyr - How to split column into two in R using separate -


this question has answer here:

i have dataset column of locations (41.797634883, -87.708426986). i'm trying split latitude , longitude. tried using separate method tidyr package

library(dplyr) library(tidyr) df <- data.frame(x = c('(4, 9)', '(9, 10)', '(20, 100)', '(100, 200)')) df %>% separate(x, c('latitude', 'longitude')) 

but i'm getting error

error: values not split 2 pieces @ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,  

what doing wrong?

specify separating character

dataframe %>% separate(location, c('latitude', 'longitude'), sep=",") 

but, extract looks cleaner since can remove "()" @ same time

dataframe %>% extract(x, c("latitude", "longitude"), "\\(([^,]+), ([^)]+)\\)") 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -