r - dplyr summarize: how to include all table columns in the output table -


i have follow dataset

# dataset x<-tbl_df(data.frame(locus=c(1,2,2,3,4,4,5,5,5,6),v=c(1,1,2,1,1,2,1,2,3,1),rpkm=rnorm(10,10))) 

if use follow command

# subset x%>%group_by(locus)%>%summarize(max(rpkm)) 

i obtained

locus max(rpkm) 1     9.316949 2     10.273270 3     9.879886 4     10.944641 5     10.837681 6     13.450680 

while i'd obtain

locus v  max(rpkm) 1     1  9.316949 2     1  10.273270 3     1  9.879886 4     2 10.944641 5     1 10.837681 6     1 13.450680 

so, i'd have in output table "v" correspondent row. possible?

try:

x %>% group_by(locus) %>%       summarize(max(rpkm), v = v[which(rpkm==max(rpkm))]) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -