【发布时间】:2019-02-20 13:38:27
【问题描述】:
我有这个 df 列:
df <- data.frame(Strings = c("ñlas onepojasd", "onenañdsl", "ñelrtwofkld", "asdthreeasp", "asdfetwoasd", "fouroqwke","okasdtwo", "acmofour", "porefour", "okstwo"))
> df
Strings
1 ñlas onepojasd
2 onenañdsl
3 ñelrtwofkld
4 asdthreeasp
5 asdfetwoasd
6 fouroqwke
7 okasdtwo
8 acmofour
9 porefour
10 okstwo
我知道df$Strings 中的每个值都将与单词one, two, three or four 匹配。而且我也知道它只会与其中一个词匹配。所以要匹配它们:
str_detect(df$Strings,"one")
str_detect(df$Strings,"two")
str_detect(df$Strings,"three")
str_detect(df$Strings,"four")
但是,我被困在这里,因为我正在尝试做这张桌子:
Homes Quantity Percent
One 2 0.3
Two 4 0.4
Three 1 0.1
Four 3 0.3
Total 10 1
【问题讨论】: