-4

I want to add the two numeric variables (strike1 and boycott1) together to get a 'protest' variable that accounts for each type of protest. To give an example, the first value on this new variable should be: 2:3598. I have used the method below on other variables and it worked, does anybody know what might be happening this time that it is coming out different?

>table(strike
strike
           Not at all                  Once                 Twice            
             2055                  2555                   840                   
Three times .         More than three times
383                   605 
> table(boycott)
boycott
           Not at all                  Once                 Twice           
             1543                  2139                   625                   
 Three times .      More than three times
    214                    426
> strike1<-as.numeric(strike)
> boycott1<-as.numeric(boycott)
> table(strike1)
strike1
   1    2    3    4    5 
2055 2555  840  383  605 
> table(boycott1)
boycott1
   1    2    3    4    5 
1543 2139  625  214  426 
> protest<-strike1+boycott1
> table(protest)
 protest
  2   3   4   5   6   7   8   9  10 
604 284 895 179 193 124  72  38  93 
 > table(strike1, boycott1)
       boycott1
strike1   1   2   3   4   5
      1 604 154  31  10  35
      2 130 843  83  16  19
      3  21  83  98  24  13
      4   3  37  45  36  12
      5   7  36  23  26  93

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • 1
    How would the first value be 2:3598? And what formatting is that? 2055+1543=3598, should this not be the first value? – Chabo Jan 03 '19 at 15:23
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 03 '19 at 16:26

2 Answers2

0

To get the output you want, try table(strike) + table(boycott). This will give you a total showing how many people gave each response to strike, added to the number who gave that response to boycott. It's a little hard for me to make sense of what this is measuring, though.

That's also not going to be measured at the individual level like strike and boycott are. If you want a variable measuring overall participation in protests, you're better off doing something like

strike1 + boycott1 # your original approach

or

(strike1 + boycott1)/2 # on the scale of the original variables

Joseph Clark McIntyre
  • 1,094
  • 1
  • 6
  • 6
  • Thanks for answering, it just seems to me that the strike1+boycott1 answer seems to have very low numbers considering the participation in strike1 and boycott1 separately. Also, when I do addition like that on other variables I get the kind of answer I was expecting. Do you think there could be some reason that these variables give a different kind of answer? – Sophie Fitzpatrick Jan 04 '19 at 10:00
  • I don't think those numbers are low, I think you may be misinterpreting them. Take the first element. There are 604 people for whom strike + boycott = 2 (i.e., 604 people who put 1 for both strike AND boycott; you can also see that in the crosstab). There are 284 people with a 3, so 284 people for whom either strike = 1 OR boycott = 1, and the other is 2. Etc.... Just notice that when you add them together, you'll no longer have the categories of the original variables. Other variables might be measured in such a way that their sum is what you expect (e.g. Likert-type items). – Joseph Clark McIntyre Jan 04 '19 at 14:36
0

What you are doing is pairwise addition. You will only get 2 when both strike1 and boycott1 are equal to 1. If strike1[i] == 1 and boycott1[i] == 2, then protest[i] == 3. Depending on what exactly you are trying to do, this may actually be what you want (supposing that your observations are paired).

To get the answer you were expecting, you would need to do:

protest <-  table( 2 * strike1 ) + table( 2 * boycott1 )  

but I would caution against doing this, as it doesn't appear (at least to me) that this would be meaningful. Then again, there may be something I'm missing about what your goal is.

Also, did you receive a warning message in your line where you added strike1 and boycott1 together? Something like:

In protest<-strike1+boycott1:
  longer object length is not a multiple of shorter object length

because I think it should have generated that warning.

AColeman
  • 485
  • 3
  • 8