我在資料框中有列 sell_details。seller_details列中資料的一個示例是:
1. 8ysl9a1301 Active 3 hours ago chat now view shop Ratings10products996 response rate28% response
2. showcasemywardore Active 3 hours ago chat now view shop Ratings773products5k response rate70% response
3. zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response
4. airspacemy.os Active 14 minutes ago chat now view shop Ratings1.2kproducts2k response rate70% response
5. zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response
我只想提取回應率的百分比。
預期輸出:
1. 28
2. 70
3. 93
4. 70
5. 93
謝謝
資料
structure(list(seller_details = c("8ysl9a1301 Active 3 hours ago chat now view shop Ratings10products996 response rate28% response",
"showcasemywardore Active 3 hours ago chat now view shop Ratings773products5k response rate70% response",
"zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response",
"airspacemy.os Active 14 minutes ago chat now view shop Ratings1.2kproducts2k response rate70% response",
"zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response"
)), class = "data.frame", row.names = c(NA, -5L))
uj5u.com熱心網友回復:
這是否有效:
library(dplyr)
library(stringr)
df %>% mutate(percent = str_extract(col, '(?<=rate)\\d{2,3}'))
col percent
1 8ysl9a1301 Active 3 hours ago chat now view shop Ratings10products996 response rate28% response 28
2 showcasemywardore Active 3 hours ago chat now view shop Ratings773products5k response rate70% response 70
3 zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response 93
4 airspacemy.os Active 14 minutes ago chat now view shop Ratings1.2kproducts2k response rate70% response 70
5 zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response 93
使用的資料:
df
col
1 8ysl9a1301 Active 3 hours ago chat now view shop Ratings10products996 response rate28% response
2 showcasemywardore Active 3 hours ago chat now view shop Ratings773products5k response rate70% response
3 zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response
4 airspacemy.os Active 14 minutes ago chat now view shop Ratings1.2kproducts2k response rate70% response
5 zanzea.os Active 37 minutes ago chat now view shop Ratings290.5kproducts6.6k response rate93% response
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/316074.html
上一篇:根據條件更新多行
