How to abbreviate long names in a dataframe for R?

霸气de小男生 提交于 2019-11-29 15:23:10

dataframe.name$abbr is a vector of all abbreviations in the dataframe, not just a single name.

It is the reason all entries in dataframe.name$abbr are being set to NA; the last name is in the dataframe is 25 characters or less, so all entries in dataframe.name$abbr are assigned NA.

@brettljausn has a decent suggestion: just do away with the NAs completely and only truncate where the character count exceeds 25.

Something like this should work a treat:

dataframe.name$abbrv <- substring( dataframe.name$org_name, 0, 25 )

I would try to use abbreviate first though:

dataframe.name$abbrv <- abbreviate( dataframe.name$org_name )
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!