DS4PS / cpp-527-fall-2020

http://ds4ps.org/cpp-527-fall-2020/
0 stars 1 forks source link

Lab 04 Part I Q2 #27

Open krbrick opened 3 years ago

krbrick commented 3 years ago

Hello data people- I'm trying every which way to identify blank strings in mission statements. I've tried grep("^\\s[^a-z]$", mission) "^\\s[^a-z]+[^0-9]+$" etc. etc. I have also looked at the transformative route: blank.missions <- dat %>% mutate (dat$mission,ch.count = strsplit(mission)) %>% dplyr::n()

also, for Q3, I can clean the missions of spaces with a function, but counting those only at the end using grepl("\\s$",dat$mission) %>% sum() doesn't seem right.

tips, pointers, self-checks appreciated.

lecy commented 3 years ago

I'm trying every which way to identify blank strings in mission statements.

What about something like?

grepl( " {1,}", titles )

Otherwise, my main advice for all of these is to create a few test cases where you know the answer and test your code until you are convinced it works.

> x <- c( "a ", "b  ", "c   ", "d", "e f g", " h i   j" )
> grep( " {1,}$", x, value=T )
[1] "a "   "b  "  "c   "
malmufre commented 3 years ago

@krbrick what I have done for Q2 is this:

grep( pattern="[[:blank:]]", x=dat$mission, value=TRUE ) %>% head() %>% pander()
grepl("[[:blank:]]",dat$mission)%>% sum()