You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中筛选数据集报错:object of type 'closure' is not subsettable

问题解决:object of type 'closure' is not subsettable

核心错误原因

你写的filter[cut, 3, 5]里,filter是dplyr包中的函数(属于closure类型),不是可子集化的数据对象,所以不能用方括号[]做提取操作——这就是报错的直接原因。你要操作的是已经用select得到的cut数据集,不是filter函数。

正确的提取方式

你已经通过select得到了cut这个数据集(data.frame/tibble类型),要提取指定位置的内容,分两种场景:

1. 基础R语法(直接子集提取)

  • 提取第3行、第5列的单个数值:
    filtered_data <- cut[3, 5]
    
  • 提取第3到第5行的所有列:
    filtered_data <- cut[3:5, ]
    
  • 提取所有行的第3到第5列:
    filtered_data <- cut[, 3:5]
    

2. dplyr风格语法(和select统一)

如果你习惯用tidyverse的语法,可以结合slice(选行)和select(选列):

  • 提取第3行第5列的单个数值:
    library(dplyr)
    filtered_data <- cut %>% slice(3) %>% pull(5)
    
  • 提取第3-5行、第3-5列的数据集:
    library(dplyr)
    filtered_data <- cut %>% slice(3:5) %>% select(3:5)
    

补充说明

你用read_csv2('df')读取数据的方式是正确的——德国PKS数据库的CSV用分号做分隔符,read_csv2正好适配这种格式,这部分和报错无关。后续用ggplot绘图时,确保filtered_data是标准的数据框/tibble即可。

内容的提问来源于stack exchange,提问作者Bralor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 05:36:03