我在通过降价将此文件另存为pdf时遇到问题。一切都节省下来,直到我到达hist()
的块,我得到错误closure is not subsettable withCallingHandlers -> withVisible-> eval ->hist
我试着环顾四周并检查变量/对象是否保存为常用函数。任何帮助都会很好!
```{r eval=FALSE}
Study<-read.csv("Data.csv")
```
Recode Age column into oridinal variable and store into new column
```{r eval=FALSE}
Study$Age2 <- as.factor( # Define new column as a factor/categorical variable
case_when(Study$s1 <= 65 ~ 'Young-Old',
between(Study$s1, 66, 75) ~ 'Med-Old',
between(Study$s1, 76, 85) ~ 'Old',
Study$s1 >= 86 ~ 'Old-Old'
)
)
```
Conduct histogram to illustrate patients' age distribution
```{r, echo=FALSE}
hist(as.numeric(Study$Age2), main = "Age Distribution", xlab = "Age Range")
```
答案 0 :(得分:2)
您的问题是,前两个代码块未被评估,因此数据不适用于块#3。 因此,如果您将代码更改为
```{r}
Study<-read.csv("Data.csv")
```
Recode Age column into oridinal variable and store into new column
```{r}
Study$Age2 <- as.factor( # Define new column as a factor/categorical variable
case_when(Study$s1 <= 65 ~ 'Young-Old',
between(Study$s1, 66, 75) ~ 'Med-Old',
between(Study$s1, 76, 85) ~ 'Old',
Study$s1 >= 86 ~ 'Old-Old'
)
)
```
渲染过程完全运行。
然而,这个问题很奇怪,因为r和eval = F之间没有逗号,所以eval = F
是块的名称,但也不会被计算。如果您不想在输出文件中包含代码,可以添加{r, include = F}
。