gpt4 book ai didi

r - 我怎样才能让这个 gsub 函数为我工作?

转载 作者:行者123 更新时间:2023-12-04 09:15:11 25 4
gpt4 key购买 nike

对 R 非常陌生,并且正在通过尝试构建模型来即时学习很多东西。我试过寻找解决方案,但没有找到任何东西。
我有一个名为 HPPH 的数据框,看起来像这样。我正在尝试将其重新格式化为一个数字。 例如:39' 11"更改为 39.11

      player_name      PH        
<chr> <chr>
1 Chad Campbell "39' 11\""
2 Charl Schwartzel "39' 7\""
3 Ángel Cabrera "39' 6\""
4 Vaughn Taylor "39' 4\""
5 Stephen Ames "39' 4\""
当我使用 gsub("' ", ".", HPPH$PH)我得到这个结果:
> gsub("' ", ".", HPPH$PH)
[1] "39.11\"" "39.7\"" "39.6\"" "39.4\"" "39.4\"" "39.1\"" "39.1\"" "39.0\"" "38.10\"" "38.4\"" "40.7\""
[12] "38.2\"" "38.1\"" "38.1\"" "37.7\"" "37.4\"" "37.2\"" "37.1\"" "37.0\"" "36.11\"" "36.9\"" "36.8\""
[23] "38.2\"" "36.5\"" "40.9\"" "40.10\"" "48.11\"" "40.10\"" "47.3\"" "45.11\"" "45.10\"" "45.7\"" "45.5\""
[34] "44.7\"" "43.8\"" "43.1\"" "42.10\"" "41.6\"" "40.10\"" "46.3\"" "36.4\"" "36.2\"" "36.0\"" "29.8\""
[45] "29.10\"" "29.10\"" "35.10\"" "35.9\"" "35.7\"" "35.6\"" "35.5\"" "35.5\"" "35.2\"" "35.2\"" "35.0\""
[56] "34.8\"" "34.8\"" "34.4\"" "34.0\"" "33.9\"" "33.6\"" "33.5\"" "33.1\"" "33.0\"" "31.10\"" "31.5\""
[67] "31.3\"" "31.0\"" "30.11\""
所以它似乎在做它应该做的事情,但是当我查看 HPPH 时,它并没有改变任何东西。
> head(HPPH)
# A tibble: 6 x 2
player_name PH
<chr> <chr>
1 Chad Campbell "39' 11\""
2 Charl Schwartzel "39' 7\""
3 Ángel Cabrera "39' 6\""
4 Vaughn Taylor "39' 4\""
5 Stephen Ames "39' 4\""
6 David Toms "39' 1\""
如果我用 HPPH$PH <- gsub("' ", ".", HPPH$PH) 分配它它变成了一个值,当我使用 View(HPPH) 时,它现在显示为这样。
HPPH

最佳答案

我们需要将它分配给对象

HPPH$PH <- gsub("' ", ".", HPPH$PH)

关于r - 我怎样才能让这个 gsub 函数为我工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63257160/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com