I\'m working with a dataframe that has really long names that is more than 25 characters. I\'m trying to make a bar graph (with plotly) with all of these organizations name,
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 NA
s 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 )