stringr function to concatenate vector of words separated by comma with “and” before last word

后端 未结 2 867
心在旅途
心在旅途 2021-01-22 12:23

I know I can easily write one, but does anyone know if stringr (or stringi) already has a function that concatenates a vector of one or more words separated by commas, but with

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 12:48

    You can use the knitr::combine_words function

    knitr::combine_words(letters[1:2])
    # [1] "a and b"
    knitr::combine_words(letters[1:3])
    # [1] "a, b, and c"
    knitr::combine_words(letters[1:4])
    # [1] "a, b, c, and d"
    

提交回复
热议问题