I have a dataframe (say x) in R:
> x
Height Weight Gender
5 60 m
5 70 m
6 80 m
4 90 m
4 60 m
5 70 f
5 80 f
6 60 f
4 90 f
4 60 f
I need an R code that will produce a new dataframe, say y, that takes the subset of X by Gender and only the first three rows of each gender (1:3) to give the result as follows.
>y
Height Weight Gender
5 60 m
5 70 m
6 80 m
5 70 f
5 80 f
6 60 f