Given a data frame in the form:
group val
A 10
A 1
B 9
C 6
...
I'd like to sample the val in each group randomly, with a new data frame as result. The problem is that the number of val in each group is different, so I can't use sample() directly. Now I'd like to determine the sample size in a if-else condition: if the number of val is higher than, let's say, 3, then three vals are sampled. Otherwise all the val are taken as samples. How can I do that? Thank you in advance!