覆盖使用Dplyr-R过滤的data.frame上的值

问题描述

我有一个名为ERROR: /home/odroid/buildFile/tensorflow/tensorflow/tensorflow/core/distributed_runtime/eager/BUILD:148:1: C++ compilation of rule '//tensorflow/core/distributed_runtime/eager:remote_tensor_handle_data' failed (Exit 1) tensorflow/core/distributed_runtime/eager/remote_tensor_handle_data.cc: In function 'void tensorflow::{anonymous}::DestoryRemoteTensorHandle(tensorflow::EagerContext*,tensorflow::eager::EagerClient*,tensorflow::uint64,int)': tensorflow/core/distributed_runtime/eager/remote_tensor_handle_data.cc:30:12: error: 'class tensorflow::EagerContext' has no member named 'GetContextId'; did you mean 'NewContextId'? if (ctx->GetContextId() != context_id) { ^~~~~~~~~~~~ NewContextId Target //tensorflow:libtensorflow_cc.so failed to build 的数据框,需要更改列cleandata上的值。

我可以从dplyr中找到要用agefilter函数替换的值。

select

我只需要将这些NA替换为8。 如下所述使用mutate不会更新原始> str(cleantrain) 'data.frame': 891 obs. of 9 variables: $ train$PassengerId: int 1 2 3 4 5 6 7 8 9 10 ... $ survived : Factor w/ 2 levels "0","1": 1 2 2 2 1 1 1 1 2 2 ... $ Title : Factor w/ 17 levels "Capt","Col","Don",..: 12 13 9 13 12 12 12 8 13 13 ... $ fare : num 7.25 71.28 7.92 53.1 8.05 ... $ sbsp : int 1 1 0 1 0 0 0 3 0 1 ... $ parch : int 0 0 0 0 0 0 0 1 2 0 ... $ alone : Factor w/ 2 levels "0","1": 1 1 2 1 2 2 2 1 1 1 ... $ familysize : Factor w/ 9 levels "1","2","3","4",..: 2 2 1 2 1 1 1 5 3 2 ... $ age : num 22 38 26 35 35 NA 54 2 27 14 ... # Column title is equal to "Master" and Column age is NA > cleantrain %>% filter(Title == "Master" & is.na(age)) train$PassengerId survived Title fare sbsp parch alone familysize age 1 66 1 Master 15.2458 1 1 0 3 NA 2 160 0 Master 69.5500 8 2 0 11 NA 3 177 0 Master 25.4667 3 1 0 5 NA 4 710 1 Master 15.2458 1 1 0 3 NA data.frame

cleantrain

我可以使用mutate来做到这一点吗?是否有不需要for / if循环的Dplyr / quick函数? #learningR

解决方法

如果要使用固定值更新行,则@akrun的replace解决方案将起作用。通常,您必须使用ifelse函数,

cleantrain <- cleantrain %>% 
  mutate(age = ifelse(Title == 'Master' & is.na(age),8,age))

相关问答

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