使用 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 . 我正在尝试使用 _countersetState,但返回的都是 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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...