【发布时间】:2021-06-02 16:50:27
【问题描述】:
在 R 中,我想递归地遍历数据框的列并选择每一列以针对给定列制作箱线图。 这是我的尝试
#define dataframe
library(ggplot2)
df <- mpg
#get unique column names
IDs <- unique( colnames(df) )
for (name in IDs){
#goal: store column as a data frame, actual: store column as a list
temp <- df[name]
#plot column of data vs cty miles per gallon
boxplot(temp ~ df$cty)
}
我收到此错误(因为它需要是数据框而不是列表):
统计错误::model.frame.default(formula = temp ~ df$cty) :
变量“temp”的类型(列表)无效
【问题讨论】: