Push up and tighten Dataframe. General solution

前端 未结 1 1092
情歌与酒
情歌与酒 2020-12-21 23:46

I want to push up (metaphorically) the dataframe in ordner to get rid of the spaces (NA-Values)

My Data:

> dput(df1)
structure(list(ID = c("CN1         


        
相关标签:
1条回答
  • 2020-12-22 00:05
    do.call(rbind,
            lapply(split(df1, df1$ID), function(a)
                data.frame(ID = a$ID[1], lapply(a[-1], sum, na.rm = TRUE))))
    #           ID       v1    v2  v2.1
    #CN1-1   CN1-1 0.376730 0.732 0.357
    #CN1-10 CN1-10 1.019972 0.000 0.816
    #CN1-11 CN1-11 0.515152 0.748 0.519
    #CN1-12 CN1-12 0.375139 0.466 0.206
    #CN1-13 CN1-13 0.508125 0.570 0.464
    
    0 讨论(0)
提交回复
热议问题