Error in cool_function[1] : object of type 'closure' is not subsettable

目录

Error in cool_function[1] : object of type 'closure' is not subsettable

问题:

解决:

完整错误:


问题:

#函数怎么能被索引那,函数计算返回的结果有可能是可以索引的。

#define function
cool_function <- function(x) {x <- x*5return(x)
}#define data
data <- c(2, 3, 3, 4, 5, 5, 6, 9)#apply function to data
cool_function(data)#attempt to get first element of function
cool_function[1]

#其他类似错误

#attempt to subset mean function
mean[1]Error in mean[1] : object of type 'closure' is not subsettable#attempt to subset standard deviation function
sd[1]Error in sd[1] : object of type 'closure' is not subsettable#attempt to subset table function
tabld[1]Error in table[1] : object of type 'closure' is not subsettable

解决:

#typeof获取数据类型

#print object type of function
typeof(cool_function)[1] "closure"

#正确的操作

#apply function to just first element in vector
cool_function(data[1])#apply function to every element in vector
cool_function(data)

完整错误:

> #define function
> cool_function <- function(x) {
+     x <- x*5
+     return(x)
+ }


> #define data
> data <- c(2, 3, 3, 4, 5, 5, 6, 9)

> #apply function to data
> cool_function(data)
[1] 10 15 15 20 25 25 30 45

> #attempt to get first element of function
> cool_function[1]
Error in cool_function[1] : object of type 'closure' is not subsettable
>

Error in cool_function[1] : object of type ‘closure‘ is not subsettable相关推荐

  1. R语言中类别为‘closure‘的对象不可以取子集(Error:object of type ‘closure‘ is not subsettable)

    最开始有package没载入,或者这一段codes中的 variable/ dataframe/ data table/ 名称有误,检查一下拼写/大小写/特殊字符/括号这些,或者重新手打一遍,基本能解 ...

  2. cannot pass non-trivial object of type 'string' to variadic function

    Scanning dependencies of target algorithm [ 50%] Building CXX object CMakeFiles/aaa.cpp.o error: can ...

  3. Pytorch 类型错误:Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor.

    Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor Pytorcht调试过程中,将数据传入模 ...

  4. JSON parse error: No suitable constructor found for type

    错误信息: 2019-02-19 09:17:58,678 [http-nio-8080-exec-1] WARN org.springframework.web.servlet.mvc.suppor ...

  5. redis存取list<T>,及bug:Failed to serialize object of type: class com.google.common.collect.Lists$Revers

    Redis存取List 实体类必须序列化,对于redis这种nosql数据库,实例化很重要,很多文章也都介绍了必须实例化,在配置redisTemplate时也会配置序列化规则: <bean id ...

  6. Vue在浏览器报错Uncaught Error: Cannot find module ‘[object Object]‘

    报错信息: Uncaught Error: Cannot find module '[object Object]' at webpackEmptyContext (eval at ./src/api ...

  7. DefaultSerializer requires a Serializable payload but received an object of type [reggie.common.R]

    目录 使用SpringCache,底层缓存技术是redis后报错: ERROR 30804 --- [nio-8080-exec-6] o.a.c.c.C.[.[.[/].[dispatcherSer ...

  8. PHP“Cannot use object of type stdClass as array”

    php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误 错误: Cannot use object of type stdClass as arr ...

  9. python3运行报错:TypeError: Object of type ‘type‘ is not JSON serializable解决方法(详细)

    python3运行报错:TypeError: Object of type 'type' is not JSON serializable解决方法(详细) 参考文章: (1)python3运行报错:T ...

  10. Flask API TypeError: Object of type 'Response' is not JSON serializable

    Flask API TypeError: Object of type 'Response' is not JSON serializable 错误代码: session['image'] = str ...

最新文章

  1. python类方法可以访问类变量_python类变量可以从类方法访问? - python
  2. 【C 语言】数组 ( 多维数组做函数形参退化为指针过程 | int array[2][3] -> int array[][3] -> int (*array)[3] )
  3. c++结构体定义和使用_[day day go]结构体amp;给结构定义方法
  4. javafx按钮设计风格_Java,JavaFX的流畅设计风格按钮,切换按钮和工具提示
  5. RocketMq单机和集群搭建教程
  6. java两个字符串的重复率检查
  7. 信息收集-CDN绕过
  8. python selenium 等待元素出现_Selenium(Python)等待元素出现
  9. 子平真诠释疑笔记(五)
  10. qt5把qt_zh_CN.qm加载了,但QTextEdit的右键菜单仍然是英文,而QLineEdit的倒是中文。怎样设置使得QTextEdit的右键菜单是中文
  11. 02_Pulsar的集群架构、架构基本介绍、Pulsar提供的组件介绍、Brokers介绍、Zookeeper的元数据存储、基于bookKeeper持久化存储、Pulsar代理
  12. linux下的hiredis的安装和使用(一)
  13. “倔驴”一个h5小游戏的实现和思考(码易直播)——总结与整理
  14. hadoop常用命令及端口
  15. 河南新乡:牧野区王村镇手绘文明墙巩固文明果
  16. 条码软件如何实现扫描二维码显示汉字
  17. div与p标签均为块级元素,区别是什么?
  18. 微型计算机控制技术:模拟量输入通道 简述题 + ADC接口电路设计分析
  19. 论文阅读(二):Decomposing Motion and Content for Video Generation
  20. 华为桌面云如何部署Linux,华为桌面云安装部署指南(19页)-原创力文档

热门文章

  1. 计算机信息安全专业代码0839,网络安全/信息安全专业大学排名(2017-2018-安全导航)...
  2. SQL语句:连接查询
  3. 违背基本假设的几种情况——自相关性(R语言)
  4. 手机扫描电脑二维码登录原理
  5. web项目缺少web组件才能与vs一起运行,带razor语法的 asp.net web pages 2.0.0.1
  6. 写给后端程序员的前端开发流程与正确姿势.
  7. 云服务器ASF挂卡(1)——steamcommunity社区本地反代
  8. C语言编程学习必备的一些网站,干货收藏!
  9. 在线人民币数字金额转成美元金额大写工具
  10. 这是不是你想要的h5手机端弹窗