所以我是R的新手,我已经成功获得了一个盒子情节。但我所做的却是凌乱而且非常低效。为了帮助我学习,我希望学习一种更简单的方法来完成我的工作。
我会在下面留下我的代码。
food_coded <- subset(data, select=c("comfort_food_reasons_coded"))
head(food_coded)
stress <- length(which(food_coded == 1))
boredom <- length(which(food_coded == 2))
depression <- length(which(food_coded == 3))
print(depression)
hunger<- length(which(food_coded == 4))
laziness<- length(which(food_coded == 5))
cold_weather<- length(which(food_coded == 6))
happiness <- length(which(food_coded == 7))
watching_tv<- length(which(food_coded == 8))
none <- length(which(food_coded == 9))
axis <- c(stress, boredom, depression, hunger, laziness, cold_weather, happiness, watching_tv, none)
#Time to make a bar graph
barplot(axis, depression)
答案 0 :(得分:1)
我们需要使用table
barplot(table(food_coded))