Re: [R] Processing a hierarchical string name

2023-06-29 Thread Kevin Zembower via R-help
Ivan and Bert, thank you so much for your help. Ivan, your solution worked perfectly. I didn't really understand how to do string processing on a vector of strings, and your solution demonstrated it for me. I modified it to work with the tidyverses' stringr library in this way: bg3_race_sum <-

Re: [R] Processing a hierarchical string name

2023-06-28 Thread Bert Gunter
I probably misunderstand what you want to do, but for: test <- c(" !!Total:", " !!Total:!!Population of one race:", " !!Total:!!Population of one race:!!White alone", " !!Total:!!Population of one race:!!Black or African American alone", " !!Total:!!Population of one race:!!American Indian and Alas

Re: [R] Processing a hierarchical string name

2023-06-28 Thread Ivan Krylov
On Wed, 28 Jun 2023 20:29:23 + Kevin Zembower via R-help wrote: > I think my algorithm for the labels is: > 1. keep everything from the last "!!" up to and including the last > character > 2. for everything remaining, replace each "!!.*:" group with a single > space. If you remove the initia

[R] Processing a hierarchical string name

2023-06-28 Thread Kevin Zembower via R-help
Hello, all I'm trying to process the names of the variables in the US Census database, that I'm retrieving with tidycensus. My end goal is to produce nicely formatted tables with natural labels. The labels as downloaded from the US Census look like this: ## Get the P1 table for block group 3 i