I have a large dataset that I try to manipulate using dplyr
. My data wrangling task requires row level string manipulation.
I am using the default rowwise()
function, and the code is working. However, the operation is taking a lot of time to complete.
VR_vehicle_GPSLocation = c("12.36556|0.74518153|xxxxxxxxxx",
"-51.75810|165.55526|xxxxxxxxxx",
"GPS nicht verfügbar",
"48.77410|171.08364|xxxxxxxxxx",
"GPS Not Available",
"0|0|N/R",
"32.18661| 170.56615|xxxxxxxxxx")
df = data.frame(VR_vehicle_GPSLocation)
jobs_location <- df %>%
rowwise() %>%
mutate(latitude = as.numeric(unlist(strsplit(as.character(VR_vehicle_GPSLocation), split='\\|'))[1]),
longitude = as.numeric(unlist(strsplit(as.character(VR_vehicle_GPSLocation), split='\\|'))[2])) %>%
select(latitude, longitude)
In order to speed up the process, I explored the multidyplyr
library without success, I am getting an error message saying that my dataset is not a data frame.
jobs_location <- jobs %>%
partition() %>%
rowwise() %>%
mutate(latitude = as.numeric(unlist(strsplit(as.character(VR_vehicle_GPSLocation), split='\\|'))[1]),
longitude = as.numeric(unlist(strsplit(as.character(VR_vehicle_GPSLocation), split='\\|'))[2])) %>%
collect()