I'm working on a project which uses Multidimensional Scaling to try and group politicians together based on voting records. My goodness of fit is high; however, I want to plot the MDS coordinates with the names of the politicians so I can draw conclusions from the computation. I am using the wordcloud library for this.
I am attempting to use regex in R using the stringr package to extract the names of the politicians from my "names" vector, the names vector contains some non-standard characters. My goal is to extract the last name and the characters in the square brackets. There are 3 different ways the names look and they are below:
- Sen. Mike Lee [R]
- Sen. Chris Coons [D, 2010-2020]
- Sen. Charles “Chuck†Grassley [R]
From the stringr package I am running this code:
str_extract("\\w+\\s\\[.+\\]$", names) # names is the vector of names
I get this error:
Error in UseMethod("type") :
no applicable method for 'type' applied to an object of class "NULL"
I'm trying to diagnose this error yet can't seem to find anything online to help.