开发者

Replacing specific values in a df with a condition

usdf$new_tests_per_thousand
 [1]    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
 [34]    NA    NA    NA    NA    NA    NA 0.001 0.002 0.002 0.003 0.004 0.005 0.005 0.005 0.007 0.010 0.014 0.026 0.035 0.039 0.043 0.081 0.118 0.150 0.180 0.226 0.225 0.219 0.237 0.310 0.340 0.384 0.403
 [67] 0.361 0.327 0.366 0.422 0.454 0.480 0.502 0.438 0.411 0.425 0.534 0.500 0.517 0.511 0.625 0.331 0.339 0.482 0.512 0.547 0.589 0.497 0.399 0.476 0.657 0.700 0.693 0.771 0.652 0.509 0.670 0.801 0.875
[100] 0.958 1.000 0.797 0.616 0.744 0.948 1.068 1.076 1.198 0.996 0.739 0.949 1.252 1.337 1.337 1.322 1.086 0.903 1.048 1.288 1.374 1.364 1.462 1.158 1.029 0.977 1.369 1.643 1.593 1.624 1.348 1.108 1.304
[133] 1.550 1.729 1.836 1.702 1.379 1.204 1.334 1.663 1.867 1.825 1.830 1.578 1.226 1.503 1.998 2.096 2.084 2.091 1.734 1.251 1.626 2.080 2.277 2.290 2.404 2.059 1.681 1.974 2.541 2.626 2.549 2.378 1.842
[166] 1.564 2.154 2.682 2.912 3.004 3.016 2.494 2.072 2.577 2.980 3.073 3.055 3.109 2.708 2.132 2.694 3.076 3.294 3.218 3.190 2.618 2.012 2.368 2.874 3.089 3.082 2.941 2.353 1.853 2.307 2.624 2.866 2.941
[199] 3.015 2.421 1.860 2.331 2.699 3.052 2.910 2.854 2.279 1.700 2.009 2.658 2.983 2.959 2.866 2.358 1.668 1.979 2.690 3.022 3.030 2.931 2.370 1.825 1.964 2.695 3.050 3.066 2.968 2.424 1.680 1.232 1.972
[232] 2.848 3.231 3.267 2.571 1.865 2.105 2.873 3.384 3.438 3.651 2.787 1.853 2.229 3.058 3.578 3.571 3.355 2.788 1.774 1.983 2.924 3.566 3.636 3.540 2.898 1.904 2.398 3.645 4.197 4.258 4.162 3.284 2.220
[265] 2.407 3.163 3.658 3.878 3.953 3.326 2.288 2.600 3.793 4.395 4.551 4.353 3.503 2.357 2.835 3.979 4.466 4.412 4.458 3.623 2.670 3.019 4.051 4.847 5.035 4.980 4.322 3.002 3.634 4.569 5.318 5.503 5.654
[298] 4.745 3.554 4.430 5.656 6.231 6.164 6.385 5.513 4.222 4.968 5.855 6.606 4.471 4.489 4.002 3.418 4.349 5.473 6.231 6.376 6.288 5.022 3.837 4.573 5.686 6.307 6.477 6.106 5.113 3.708 4.437 5.777 6.167
[331] 6.093 6.003 5.081 3.790 4.539 5.902 6.769 5.615 3.200 2.952 2.820 3.888 5.602 6.508 5.712 3.728 3.321 3.123 4.183 5.860 6.944 6.715 6.390 5.106 3.474 4.546 6.049 6.289 6.207 6.087 4.744 3.199 3.847
[364] 5.397 6.365 6.140 5.755 4.617 2.995 3.690 5.327 6.169 5.698 5.513 4.299 2.825 3.083 4.872 5.579 5.758 5.460 3.974 2.469 3.118 5.051 4.896 4.230 4.214 3.281 1.977 2.387 3.732 4.388 4.217 4.037 3.152
[397] 2.035 3.105 4.902 5.039 4.806 4.405 3.202 1.888 2.971 4.806 5.184 4.634 4.270 3.175 1.817 2.918 4.594 4.819 4.473 4.169 3.052 1.724 2.832 4.466 4.818 4.392 4.004 2.943 1.826 2.907 4.558 4.936 4.311
[430] 4.092 2.970 1.853 3.004 4.560 4.706 4.295 4.000 2.886 1.677 2.824 4.617 4.957 4.509 4.314 3.005 1.916 3.137 4.791 4.977 4.410 4.324 2.994 1.820 3.029 4.663 4.914 4.447 4.190 2.955 1.753 2.966 4.675
[463] 4.693 4.221 3.906 2.686 1.552 2.664 4.225 4.547 3.892 3.499 2.533 1.440 2.554 3.968 3.993 3.550 3.227 2.340 1.349 2.371 3.607 3.505 2.995 2.928 2.107 1.214 2.116 3.189 3.121 2.755 2.491 1.721 1.069
[496] 0.939 2.106 3.295 2.936 2.582 1.831 1.095 1.914 2.630 2.575 2.330 2.269 1.655 1.026 1.775 2.469 2.354 2.153 2.059 1.475 0.989 1.695 2.323 2.269 2.062 1.999 1.462 1.006 1.640 2.071 2.013 1.907 1.781
[529] 1.326 0.773 0.911 1.756 2.310 2.153 1.975 1.449 1.015 1.746 2.194 2.255 2.281 2.153 1.562 1.178 1.957 2.675 2.755 2.720 2.616 1.941 1.460 2.330 3.073 3.287 3.296 3.113 2.273 1.687 2.871 3.758 3.925
[562] 4.102 3.970 2.986 2.125 3.365 4.273 4.549 4.550 4.543 3.351 2.361 3.804 4.774 5.064 4.907 4.588 3.494 2.494 3.926 5.380 5.807 5.829 5.625 4.269 2.923 4.331 5.860 6.056 5.854 5.551 4.045 2.950 2.449
[595] 4.175 6.075 6.148 6.143 4.559 2.932 4.434 5.615 6.325 5.989 5.708 4.148 2.857 4.129 5.733 6.142 5.941 5.702 4.028 2.614 3.661 5.584 5.995 5.759 5.439 3.929 2.392 3.794 5.495 5.891 5.669 5.321 3.682
[628] 2.163 3.442 4.941 5.542 5.596 5.112 3.567 2.083 3.667 5.119 5.612 5.482 4.819 3.290 1.890 3.444 5.010 5.370 5.043 4.637 3.146 1.831 3.151 4.894 5.648 5.231 4.747 3.333 2.487 3.724 5.561 5.445 5.156
[661] 4.437 3.322 2.308 3.748 5.522 5.843 5.633 4.962 3.396 2.265 3.426 4.826 4.928 2.244 2.269 2.689 2.432 4.062 5.620 5.848 6.075 5.749 4.066 2.429 3.843 5.782 6.092 5.687 5.497 3.871 2.405 4.039 5.853
[694] 6.300 6.216 5.923 4.401 3.089 4.683 6.585 7.182 7.140 5.303 2.811 2.873 5.099 6.869 6.956 7.014 5.987 3.739 3.996 6.707 8.749 9.501 9.439 8.653 6.529 4.919 6.348 7.984 8.699 8.971 8.390 6.128 4.080
[727] 5.154 7.701 8.781 8.292 7.353 5.190 3.398 4.635 5.772 6.203 6.070 5.600 3.638 2.266 3.701 5.260 5.615 4.750 4.400 3.319 1.878 3.712 4.889 4.635 4.364 4.171 2.634 1.483 2.922 4.687 4.870 4.511 4.059
[760] 2.668 1.363 2.125 3.629 4.090 3.670 3.360 2.089 1.257 2.658 3.791 3.696 3.587 3.175 1.984 1.055 2.354 3.587 3.382 3.011 2.971 1.879 1.045 2.360 3.637 3.557 3.285 2.999 1.819 1.053 2.310 3.399 3.288
[793] 2.940 2.883 1.866 0.997 2.098 3.128 3.138 2.830 2.719 1.771 0.938 2.064 3.191 2.964 2.791 2.718 1.762 0.940 2.027 2.863 2.720 2.442 2.102 1.361 0.797 1.676 2.395 2.451 2.303 2.263 1.494 0.862 2.205
[826] 3.382 3.229 2.979 2.925 1.823 0.982 1.978 3.011 2.971 2.862 2.807 1.946 1.057 2.142 3.289 3.303 3.037 2.822 2.063 1.123 2.307 3.341 3.398 3.232 3.143 2.164 1.232 2.313 3.408 3.335 3.000 2.474 1.730
[859] 1.031 0.886 2.145 3.171 3.288 2.815 1.884 1.141 1.954 2.799 2.373 1.556 1.549 1.281 1.041 1.654 2.063 1.791 1.402 1.206 0.734    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
[892]    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
[925]    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
[958]    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA    NA
[991]    NA    NA    NA    NA    NA    NA    NA    NA    NA
usdf$new_tests_per_thousand[usdf$new_tests_per_thousand<3.22] <- 'LOW'
usdf$new_tests_per_thousand[usdf$new_tests_per_thousand>3.22] <- 'HIGH'
print(usdf$new_tests_per_thousand)
  [1] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
 [29] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
 [57] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
 [85] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[113] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[141] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[169] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[197] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[225] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "开发者_Python百科;HIGH"
[253] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[281] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[309] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[337] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[365] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[393] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[421] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[449] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[477] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[505] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[533] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[561] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[589] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[617] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[645] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[673] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[701] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[729] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[757] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[785] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[813] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[841] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH"
[869] "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" "HIGH" NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
[897] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
[925] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
[953] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    
[981] NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA     NA    

I just don't entirely understand why it's wrong. If I run just the "low" code line, it correctly sorts, and when I run the "high" line it also works but the combination of them fail.


After your first assignment, all of the numbers that were not updated become strings, and comparisons are now not what you would expect:

vec[vec < 3.22] <- "LOW"
vec
# [1] "LOW"  "LOW"  "LOW"  "3.33" "4.44" "5.55"
vec > 3.22
# [1] TRUE TRUE TRUE TRUE TRUE TRUE

If you want to replace them with low/high, do it all at once or into a new vector (column):

  • All at once:

    vec <- c(0.01, 1.11, 2.22, 3.33, 4.44, 5.55)
    vec <- ifelse(vec < 3.22, "LOW", "HIGH")
    vec
    # [1] "LOW"  "LOW"  "LOW"  "HIGH" "HIGH" "HIGH"
    
  • New column/vector:

    vec <- c(0.01, 1.11, 2.22, 3.33, 4.44, 5.55)
    vec2 <- character(length(vec))
    vec2
    # [1] "" "" "" "" "" ""
    vec2[vec < 3.22] <- "LOW"
    vec2[vec > 3.22] <- "HIGH"
    vec
    # [1] 0.01 1.11 2.22 3.33 4.44 5.55
    vec2
    # [1] "LOW"  "LOW"  "LOW"  "HIGH" "HIGH" "HIGH"
    


You can use dplyr for this:

usdf %>%
mutate(new_tests_per_thousand=case_when(
                              new_tests_per_thousand> 3.22 ~'HIGH',
                              new_tests_per_thousand<3.22 ~'LOW'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜