0

嘿,伙计们,我有这个:


df<-data.frame(x1=c("0.25","0.4**","0.24"),
           x2 = c("","0.72***","0.68*"),
           x3 = c("","","0.75"))
rownames(df) <- c("X2","X3","X4")
df %>% 
  rownames_to_column() %>% 
  gather(key, values,-rowname) %>% 
  filter(values %in% "[*]")

ouput:
<0 linhas> (ou row.names de comprimento 0)

预期输出:

仅选择“重要”值 * ** *** ****

# 行名 钥匙 价值观
2 X3 x1 0.4**
5 X3 x2 0.72***
6 X4 x2 0.68*
4

1 回答 1

1

您可以使用带有字符类的正则表达式来执行此操作:

df<-data.frame(x1=c("0.25","0.4**","0.24"),
               x2 = c("","0.72***","0.68*"),
               x3 = c("","","0.75"))
rownames(df) <- c("X2","X3","X4")
df %>% 
  rownames_to_column() %>% 
  gather(key, values,-rowname) %>% 
  filter(values %>% str_detect("[*]"))

用于%in%整个字符串匹配和正则表达式以匹配查询字符串的一部分。

于 2021-09-07T15:06:33.217 回答