My data is dataframe(fpo):
damIDpoG4 damSirepoG4 damGpoG4 damPhenpoG4 damTBVpoG4 damGBVpoG4
[1,] 450622 430878 4 5.540501 4.260957 3.422568
[2,] 450623 430878 4 3.046358 4.169094 3.528200
[3,] 450625 430878 4 4.515801 4.543196 3.843761
....
[50,] 450626 470878 4 4.798896 4.501067 3.875034
[51,] 450630 470878 4 4.282659 4.388037 3.830042
[52,] 450632 470878 4 3.553223 4.086484 3.571130
I want to select n number (for example 12) from damIDpoG4 for per similar group of damSirepoG4 according to MAX and or 20% damGBVpoG4 . damSirepoG4 contain 250 groups of identical numbers I try:
fpo %>% group_by(fpo[,2]) %>% sample_n(12)
but my answer is not correct. I could not consider max or percent for dplyr
thanks for attention
We need to pass the column name in group_by
(assuming that 'fpo' is data.frame/tbl_df
and not a matrix
)
fpo %>%
group_by(damSirepoG4) %>%
sample_n(12)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.