b <- c("books", " ", "animals", "frogs")
#My code:
b[!grepl("^\\s+$", b)]
[1] "books" "animals" "frogs"
#Now, I am working to figure out this solution with stringr package.
str_remove_all(b, "^\\s+$")
[1] "books" "" "animals" "frogs"
Run Code Online (Sandbox Code Playgroud)
输出显示""我的新代码失败的地方。有什么解决方案可以得到像我的第一个代码一样的结果吗?
r ×1