paste, by and data.table in r

后端 未结 2 1920
既然无缘
既然无缘 2021-01-05 07:07

I\'m trying to paste strings from a reshaped dataset. I\'m using the data.table package as follows:

m<-data.frame(x=rep(c(\"a\",\"b\"),20),y=factor(sample         


        
相关标签:
2条回答
  • 2021-01-05 07:43

    For completeness' sake, an official answer:

    If you use paste(y,collapse=",") instead, it should work.

    0 讨论(0)
  • 2021-01-05 07:44

    The toString(y) function produced the same result as paste(y, collapse = ", "), I use it as substitute for the longer paste version. So

    DT[, toString(y), by = x]
    

    would yield the outcome

    #   x                                                         V1
    #1: a v, o, q, p, t, c, y, d, n, r, o, k, v, r, t, n, e, f, g, u
    #2: b y, j, t, l, w, r, s, w, b, x, h, j, o, k, a, c, r, c, b, e
    

    which is the same for paste

    DT[, paste(y, collapse = ", "), by = x]
    
    0 讨论(0)
提交回复
热议问题