“必须使用有效的下标向量对元素进行子集化x 下标必须是一个简单的向量,而不是矩阵”部分

问题描述

我正在尝试对大型数据集运行递归分区,但继续遇到我无法解决错误代码如下:

library(rpart)
library(haven)
library(tidyverse)

my.data <- read_sav("my.data.sav")

goal_binary_notxhx <- rpart(binary_change_6mo ~ fm9008a + fm9009a + fm9010a + fm9011a + fm9012a 
                            + fm9013a + fm9014a + fm9015a + fm9016a + fm9017a + fm9018a,data = my.data,method = 'anova',control = (xval = 10))

使用 dput 的数据:

structure(list(fm9008a = structure(c(90,89,79,90,77),label = "Living in House",format.spss = "F4.2",display_width = 9L),fm9009a = structure(c(0,14),label = "Living Rent Free",fm9010a = structure(c(0,0),label = "Living in Halfway House",fm9011a = structure(c(0,label = "Living Homeless",fm9012a = structure(c(2,1,3,2,label = "Living Under Medical Care",fm9013a = structure(c(0,label = "Alcohol Sessions",fm9014a = structure(c(0,label = "Drug Sessions",fm9015a = structure(c(0,label = "Emotional Sessions",fm9016a = structure(c(0,6,label = "12-Step Sessions",fm9017a = structure(c(63,58,4,73,63,63),label = "Work Days",fm9018a = structure(c(0,label = "School Days",display_width = 9L)),row.names = c(NA,-6L),class = c("tbl_df","tbl","data.frame"))
binary_change_6mo = structure(c(1,NA,NA),label = "Binary goal change from 0 to 6mo",format.spss = "F8.2",labels = c(`no change` = 0,change = 1),class = c("haven_labelled","vctrs_vctr","double"
))

我的错误信息如下:

Error: Must subset elements with a valid subscript vector.
x Subscript must be a simple vector,not a matrix.

我已尝试将导入的数据更改为数据框,但出现相同的错误并且不知道如何继续。

df.my.data <- as.data.frame(my.data)

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)