Extracting Numeric Data from String in R

Hello good people,
I am trying to run the code below but I’m getting the errors below:

split_location <- strsplit(hs_directory$Location.1, “\n”, simplify = TRUE)

Error in strsplit(hs_directory$Location.1, “\n”, simplify = TRUE) :

unused argument (simplify = TRUE)

hs_directory <- hs_directory >
mutate(lat_long = split_location[,3])

Error: object ‘split_location’ not found

Kindly help

Strsplit does not have a “simplify” argument, so I think that’s the source of your error.

See if this is throwing an error: strsplit(hs_directory$Location.1, “\n”)

When I run that, I get the below error:

Error in strsplit(hs_directory$Location.1, “\n”) : non-character argument

Try this:

split_location <- strsplit(as.character(hs_directory$Location.1), "\n")

Also, parameter simplify=TRUE exists for function str_split from stringr package.
Official doc: https://www.rdocumentation.org/packages/stringr/versions/1.4.0/topics/str_split

Thanks for the response. I tried the code earlier and it worked. Thanks for the support.

Glad you have found the solution. If any answer helps, please, mark it as solution for future readers. Thanks! :slight_smile:

When I run the code as below:

split_location <- strsplit(as.character(hs_directory$Location.1), split = “\n”)

hs_directory <- hs_directory >
mutate(lat_long = split_location[,3])

I get the error:

Error in split_location[, 3] : incorrect number of dimensions

Any help will be highly appreciated.

You need to have a closer look at split_location variable.
str(var) and dim(var) could be useful here…

dim(split_location) returns NULL

str(split_location) returns below example:

$ : chr [1:3] “1396 Broadway” “Brooklyn, NY 11221” “(40.688925542, -73.921084099)”