Replacing words by numbers in multiple columns of a data frame in R
I guess this is off-topic but here's a reproducible code:

#Preparing mocking data
&gt;set.seed(123) #for reproducibility
&gt;Party &lt;- sample(c('D', 'N','R'), 10, replace = TRUE) #sample random values
&gt;d &lt;- data.frame(Party) #put values into a dataframe

# Here's how you substitute the values in just one line. This operation is vectorised.
&gt;d$Response &lt;- ifelse(d$Party=='R', -1, ifelse(d$Party=='D', 1, 0))


Basically in new Response column, you check if R and assign -1, if not you check if D and assign 1; otherwise you assign 0.

&gt; d
   Party Response
1      D        1
2      R       -1
3      N        0
4      R       -1
5      R       -1
6      D        1
7      N        0
8      R       -1
9      N        0
10     N        0