-2

Data set has question: What country have you visited? Subject can pick multiple countries.

So...

    country
1.  1, 2, 3
2   1,
3   2

Would like item to look like:

    country_1 country_2 country_3
1.    1           2       3
2     1
3     2

What syntax would be helpful here?

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Nick
  • 21
  • 6

1 Answers1

0

You want to attach dimnames to your array when you make an array in r.

The way that the array function works is array(data=c(),dim=c(),dimnames=())

col_names = c("country_1","country_2","country_3")
row_names = c("1.","2.","3.")

foo = array(c(1,1,2,2,0,0,3,0,0),dim = c(3,3),dimnames= list(row_names,col_names))

print(foo)

Output

   country_1 country_2 country_3
1.         1         2         3
2.         1         0         0
3.         2         0         0
Bonson
  • 11
  • 3