Load library and test.csv
library(tidyverse)
library(here)
# read test csv containing coordinate pairs
test <- read_csv(here('test', 'test.csv'))
Glimpse test data set containing coordinate pairs
# glimpse test data
glimpse(test)
## Rows: 2
## Columns: 1
## $ testcolumn <chr> "[{'y':50,'x':50}, {'y':53','x':35}]", "[{'y':55,'x':35}, {…
Use seperate_wider_delim to split single column into
multiple
# split test field into multiple columns
test2 <- separate_wider_delim(test,
# delimiter, in this case, I used ','
delim=',',
# input column/field in data frame to split,
cols=testcolumn,
# enter name of the new columns to be created (sequential based on delimiter)
names=c("start_y", "start_x","end_y","end_x"), too_many="merge") %>%
# mutate across all column and parse numbers
mutate(across(everything(), ~ readr::parse_number(.x)))
# resulting data frame with multiple columns (still needs some cleaning but mostly there!)
glimpse(test2)
## Rows: 2
## Columns: 4
## $ start_y <dbl> 50, 55
## $ start_x <dbl> 50, 35
## $ end_y <dbl> 53, 19
## $ end_x <dbl> 35, 75
head(test2)
## # A tibble: 2 × 4
## start_y start_x end_y end_x
## <dbl> <dbl> <dbl> <dbl>
## 1 50 50 53 35
## 2 55 35 19 75