r - 删除自定义字符串并转换科学计数法
问题描述
样本
data=data.frame("first"=c("A","B","C"),
"one"=c(1:3),
"two"=c("2.1e-003*", 5, "1.9e-9*"),
"three"=c("1.6e-002*", 5, "8.1e-2*"))
我的目标是删除“*”并将科学记数法转换为数字。
我试过无济于事
WANT=gsub("\\*.*","",data)
解决方案
library("tidyverse")
data <- data.frame(
"first" = c("A", "B", "C"),
"one" = c(1:3),
"two" = c("2.1e-003*", 5, "1.9e-9*"),
"three" = c("1.6e-002*", 5, "8.1e-2*")
)
data %>%
# Cast unhelpful `factor` columns to `character`
mutate_at(vars(two, three), as.character) %>%
mutate_at(vars(two, three), parse_number) %>%
# You can turn off the scientific notation
# but you end up with a lot of zeros...
mutate_at(vars(two, three), format, scientific=FALSE)
#> first one two three
#> 1 A 1 0.0021000000 0.016
#> 2 B 2 5.0000000000 5.000
#> 3 C 3 0.0000000019 0.081
由reprex 包(v0.2.1)于 2019 年 3 月 29 日创建
推荐阅读
- meld - 如何在三向合并选项卡仍打开时手动将文件标记为已解决
- selenium - 如何区分硒/黄瓜参数化数据测试的测试描述?
- android - 如何从android studio中的商家应用程序向客户端应用程序发送推送通知?
- asp.net-mvc - MVC 报告查看器呈现/响应问题
- react-native - 错误:GoogleSignIn.null:DEVELOPER_ERROR 在 expo-google-sign-in
- python - 类点\继承 - 任务检查
- windows - 删除多个文件夹中超过 x 天的文件
- python - 如何使用 OneLineIconListItem 向每个动态项目添加图标。我的代码给出了 TypeError: object.__init__() 没有参数
- model-view-controller - 如何在会话结束时更改 MVC 网站的默认登录 URL?
- python - 编写一个 python 脚本来读取两个参数,它们是我需要到达并打印状态的主机和端口?