Str_Split with double periods

Hi all,
I am trying to separate the first column into three columns: Census tract, county, and estimate ( total, below poverty, and percent below poverty).

How can I split the first column by the ".."? I tried

attempt<- str_split(take1, pattern = '[..]')
attempt
#  [1] "Census"   "Tract"    "201"      ""         "Alamance" "County"  
# [7] ""         "North"    "Carolina" ""         "Total"    ""        
# [13] "Estimate"

As shown above, the output is split by every period, not every double period. Is there a way around this or a better way to split the data? Thank you in advance for any insight!

Try this:

label = "Alamance.County..North.Carolina"
str_split(label, "[\\.]{2}")
[[1]]
[1] "Alamance.County"      "North.Carolina"

The . is a special character and needs to be escaped with \\. The {2} represents a length of two characters in the [].

1 Like

That fixed it, thank you!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.