I want to list in array format how many in each Diet group (there are four) have Time > 21.
I have tried to solve this in RStudio.
data(ChickWeight)
newdata <- subset(ChickWeight, Time >= 21, select=Diet)
In order to find how many observations are in newdata, I used
nrow(newdata)
,
but I would like to find out how many observations meet the criteria just by making it a part of this expression:
newdata <- subset(ChickWeight, Time >= 21, select=Diet)
so that when I display newdata
the table will also contain the number of observations that meet the criteria in a new column.
Desire output:
Diet Number Observations
1 200 (I just created the numbers for this column as examples)
2 75
3 150
4 100
Is there a way to do that?