Skip to content

[Introduction:ufo] Strsplit  #40

@tianyihu1988

Description

@tianyihu1988

In the following sentence, strsplit won't feedback a error when no comma in ufo$Location.
As a result, we cannot extract the "'City, State'" from "City" by the trycatch-strsplit method.

split.location <- tryCatch(strsplit(l, ",")[[1]],
error = function(e) return(c(NA, NA)))

Suggest to revised to:

get.location<-function(l)
{
split.location<-strsplit(l,",")[[1]]
clean.location <- gsub("^ ","",split.location)
if(length(clean.location)!=2)
{
return(c(NA,NA))
}
else
{
return(clean.location)
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions