如何解决使用 ifelse 和 is.na 进行变异
我有以下格式的数据,其中我需要处理的所有变量都是 "scripts": {
"start": "react-scripts start","build": "react-scripts build","test": "react-scripts test","eject": "react-scripts eject","dev": "parcel public/index.html","run": "parcel build index.html"
},
或变量名称,我需要将 NA 更改为 0,将字符串更改为 1 . 我正在尝试使用 _counter
和 setState
,但返回的都是 1。我现在唯一有效的解决方案是单独改变每个变量。
如何一次将多个变量中的所有 hashMap1 : HashMap<String,MutableList<String>> = {ab=["hello","how","are","you"],cd=["my","world"],ef = ["life","is","nice"]}
hashMap2 : HashMap<String,MutableList<String>> = {ab=["how","you","in","life"],ef = ["nice","to"],gd = ["fun"]}
更改为 0,将所有字符串更改为 1?
hashMap3 = {ab=["how",ef = ["nice"]}
由 reprex package (v0.3.0) 于 2021 年 1 月 13 日创建
解决方法
这也有效,我认为是最简单的方法。
tribble(
~black,~grey,~white,~purple,NA,"grey","purple","white","black",NA
) %>%
modify(~ ifelse(is.na(.),1))
# A tibble: 4 x 4
black grey white purple
<dbl> <dbl> <dbl> <dbl>
1 0 1 0 1
2 0 0 1 0
3 1 0 0 0
4 0 1 0 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。