问题描述
我有以下格式的数据,其中我需要处理的所有变量都是 "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