Error in **** : non-numeric argument to binary operator

目录

Error in **** : non-numeric argument to binary operator

问题:

解决:

完整错误:


问题:

想要生成新的数据列,基于已有数据列的差,但是其中一个作差的数据列不是数值型,不是数值怎么作差,OK出问题了。

#create data frame
df <- data.frame(period = c(1, 2, 3, 4, 5, 6, 7, 8),sales = c(14, 13, 10, 11, 19, 9, 8, 7),returns = c('1', '0', '2', '1', '1', '2', '2', '3'))#view data frame
df#attempt to create new column called 'net'
df$net <- df$sales - df$returns

解决:

#class查看数据类型

#display class of 'sales' column
class(df$sales)[1] "numeric"#display class of 'returns' column
class(df$returns)[1] "character"

#as.numeric转换之后再作差

#create new column called 'net'
df$net <- df$sales - as.numeric(df$returns)#view updated data frame
df

完整错误:

> #create data frame
> df <- data.frame(period = c(1, 2, 3, 4, 5, 6, 7, 8),
+                  sales = c(14, 13, 10, 11, 19, 9, 8, 7),
+                  returns = c('1', '0', '2', '1', '1', '2', '2', '3'))

> #view data frame
> df
  period sales returns
1      1    14       1
2      2    13       0
3      3    10       2
4      4    11       1
5      5    19       1
6      6     9       2
7      7     8       2
8      8     7       3

> #attempt to create new column called 'net'
> df$net <- df$sales - df$returns
Error in df$sales - df$returns : non-numeric argument to binary operator

Error in **** : non-numeric argument to binary operator相关推荐

  1. R语言报错 Error in y + 1 : non-numeric argument to binary operator 解决记录

    因为花了2天半才解决,中间痛苦的寻找,记录一下解决的流程与经验 文章目录 报错信息: 报错原因: 原代码: 报错原因解析: 1. 转置后数据类型变为character,因为numeric数据中存在ch ...

  2. R中报错Error in mut[, pos] - 1 : non-numeric argument to binary operator

    数据不是数值型,转换成数值型即可解决问题 as.numeric() > sigs.input=mut.to.sigs.input(mut.ref =sample.mut.ref ,sample. ...

  3. R语言构建随机森林模型错误解决:Error in y - ymean : non-numeric argument to binary operator

    R语言构建随机森林模型错误解决:Error in y - ymean : non-numeric argument to binary operator 目录 R语言构建随机森林模型错误解决:Erro ...

  4. R语言报错 non-numeric argument to binary operator

    R语言对数据框的数据进行求和与平均值,直接计算报错,原代码如下: mydata1 <- mutate(mydata1,sum = sale2015 + sale2016 + sale2017 + ...

  5. windows安装pycocotools错误:cl : Command line error D8021 : invalid numeric argument '/Wno-cpp'

    在安装基于keras.tensorflow实现的Mark RCNN(https://github.com/matterport/Mask_RCNN),要运行其中的demo.ipynb时,需安装pyco ...

  6. 关于R语言报错:invalid argument to unary operator(一元运算符的无效参数)---ggplot2画图问题--解决Monte Carlo模拟输出

    目录 背景 我的操作(错误 解决问题过程: 1)查找 2)尝试将画图等过程从函数中移出来 3)尝试将+geom_line(aes(y=h_mean-sqrt(h_var))移入到前面的一行中去 结果 ...

  7. 日常生活小技巧 -- “Error: Encountered an improper argument”的解决方法

    使用keil5.25兼容版本的,在debug过程中修改代码和打断点,再退出debug马上就出现该问题:Error: Encountered an improper argument. 解决方法: 工程 ...

  8. ERROR: Unrecognized command line argument: #39;use#39;

    Unrecognized command line argument: 'use' gvm- -GoLang语言多版本管理工具 基础环境 centos6.5 报错内容 gvm在命令行以外的任何地方调用 ...

  9. QT “error: error writing to -: Invalid argument”

    我所出现的问题源自不同系统下目录的写法:在linux中我们写路径一般使用斜杠/,然而在Windows下为反斜杠\. 我在Windows下使用下面的写法Qt会提示error: error writing ...

最新文章

  1. 《黑客与画家》读后感:你对技术一无所知(一些金句)
  2. odoo12 日历模块_odoo12
  3. .net 5 正式版_ASP.NET Core 3时代全新开启,DevExpress ASP.NET增强Data Grid
  4. vue中打印表格功能(重点是表格制作)
  5. 韩立刚计算机网络——第三章:数据链路层
  6. C语言 实验7-3-5 输出大写英文字母 (15分)
  7. 用Python做的整蛊小程序——整点阴间的东西
  8. mc服务器图标修改,高版本配置文件修改(添加,修改交易)
  9. 性能工具之Java分析工具BTrace入门
  10. Qt 自定义标题栏,最小化、最大化、关闭窗口,双击最大化,鼠标拖动等效果实现
  11. MIMO-OFDM系统原理及其关键技术
  12. 解决笔记本IPS屏幕发黄问题
  13. Oracle安装和配置
  14. STM32深入实践教程目录
  15. 计算机最学生写作的影响,计算机对学生英语写作影响的元分析
  16. 用PyTorch来实现手写体数字识别
  17. 4.9 朗斯基行列式
  18. 我使用的安卓软件名单
  19. Mac m1恢复出厂设置
  20. 2020年8月工作月报

热门文章

  1. 架构中的一切都是权衡
  2. 线下活动【深圳】用Leangoo做Scrum敏捷开发实战课(免费)
  3. 网络负载均衡相关技术-第四层交换功能
  4. C 关于页面刷新和combobox的使用
  5. 26 history对象
  6. Python中的生产者与消费者模式(转载)
  7. html5 css3雪花效果,HTML5 | CSS3水晶皇冠雪花形状
  8. discuz sitemap.php,discuz制作门户的百度sitemap
  9. DisARM:用于3D目标检测的位移感知关联模块(CVPR2022)
  10. CVPR2021 | PAConv:一种位置自适应卷积,点云分类、分割任务表现SOTA