How to find the mean of a continuous variable for each categorical variable

后端 未结 2 930
孤独总比滥情好
孤独总比滥情好 2021-01-27 08:21

I\'d like to plot continuous BMI on the y-axis and the categorical variable for Family Income on the x-axis and I\'d like the graph to plot the mean BMI for each category. Howev

2条回答
  •  别那么骄傲
    2021-01-27 08:55

    Here's a base solution using aggregate:

    a <- aggregate(BMI ~ FamIncome, data=nh, FUN=mean)
    barplot(a$BMI, names.arg=a$FamIncome)
    

    enter image description here

提交回复
热议问题