这段代码给了我一个错误:Error in if (is.na(s)) { : the condition has length > 1

问题描述 投票:0回答:2

请帮助解决我执行以下命令时遇到的错误:

stargazer(as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)]), 
      type="html", 
      title="Mean and Standard Deviation of Monthly Household Income by State for Rural India (Unweighted)", 
      summary=F, covariate.labels=c("S.No.", "State", "Mean", "Std.Dev."), 
      digits=0,
      notes=c("Source: Periodic Labour Force Survey, 2017-18"), 
      out=c("tb2.state-rural.hh.earnings.html"))
r if-statement stargazer
2个回答
7
投票

我也有类似的问题。对我来说,它有助于定义观星器功能之外的数据框。 原来如此

df <- as.data.frame(st_sect.hh.earnings[st_sect.hh.earnings$sector.f=="Rural",c(1,3,4)])
stargazer(df, 
      type="html", 
      title="Mean and Standard Deviation of Monthly Household Income by State for Rural India (Unweighted)", 
      summary=F, covariate.labels=c("S.No.", "State", "Mean", "Std.Dev."), 
      digits=0,
      notes=c("Source: Periodic Labour Force Survey, 2017-18"), 
      out=c("tb2.state-rural.hh.earnings.html"))

编辑(在评论中讨论之后):这样做的原因是参数输入长度不应该太长。查看下面的评论。


1
投票

不是答案,但可能是一个提示:以下代码

library(functional)
library(stargazer)

tabify <- function(models){

sgCurried = Curry(stargazer)

do.call(sgCurried, models)
}


mydf <- data.frame(Y = rnorm(15), Z = ceiling(rnorm(15)))

regr <- lm(Y ~ Z, data=mydf)

models = list(regr)

tabify(models)

...曾经在 R 4.1.2 上工作,但在 R 4.2.2 上失败(两种情况下 stargazer 都是 5.2.3),产生 OP 报告的错误。

© www.soinside.com 2019 - 2024. All rights reserved.