Printing dataframes with long strings in R

前端 未结 3 1849
挽巷
挽巷 2021-02-20 00:13

Let\'s have a dataframe with long strings in one column:

 df<-data.frame(short=rnorm(10,0,1),long=replicate(10,paste(rep(sample(letters),runif(1,5,8)),collaps         


        
3条回答
  •  我寻月下人不归
    2021-02-20 00:15

    This is one way:

    within(df, {
        long = paste(substr(long, 1, 10), "...", sep = "")
    })
    

    I use substr to get the first part of the string, than I use paste for the "...". To permanently change the characters in df, simply do:

    df = within(df, {
        long = paste(substr(long, 1, 10), "...", sep = "")
    })
    

提交回复
热议问题