concatenate adjacent strings from a vector

前端 未结 1 1846
-上瘾入骨i
-上瘾入骨i 2021-01-14 15:11

Given

qz <- quantile(c(1,2,3,4,5,6,7,8,9,10), c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0))

I want to create a vector of labels from the quantiles. C

相关标签:
1条回答
  • 2021-01-14 15:42

    head and tail give you the slices of the quantiles that you need to paste.

    x <- sprintf("$%.2f", qz)
    x
    ## [1] "$1.00"  "$2.80"  "$4.60"  "$6.40"  "$8.20"  "$10.00"
    
    paste(head(x, -1), tail(x, -1), sep=' - ')
    ## [1] "$1.00 - $2.80"  "$2.80 - $4.60"  "$4.60 - $6.40"  "$6.40 - $8.20"  "$8.20 - $10.00"
    
    0 讨论(0)
提交回复
热议问题