0

I am currently working with survey data in R studio. I originally had two csv files but I merged them into one. Both CSV files contained sample IDs. The first file also contains bivariate info, while the second contains rating as a continuous variable.

Here is a sample of the data

    ID  O1  O2  O3  O4  O5  O6  O7  O8  S1  S2  S3  S4  S5  S6  S7  S8
    22  0   1   0   1   0   1   0   1   4   6   2   6   4   3   6   2
    23  0   1   0   0   1   1   0   1   5   6   10  4   5   7   7   6
    24  0   1   1   0   1   0   0   1   7   4   7   8   7   6   3   9
    25  0   0   1   1   0   0   1   1   3   5   5   7   4   6.9 6   5
    26  0   1   0   0   1   1   0   1   2   2.5 7   5   4   5   4   3
    27  0   1   1   1   0   1   0   0   6   3   4   6   5   6   5   6
    28  0   1   1   1   0   0   0   1   7   4   2   8   2   1   4   5
    29  0   0   1   0   1   1   1   0   2   5   1   2   4   3   2   2
    30  0   1   0   1   1   1   0   0   8   2   6   7   1   7   5   4
    31  0   0   0   1   0   1   1   1   7   4   3   2   4   5   7   2
    32  0   0   1   0   0   1   1   1   4   7   5   3   1   6   2   3
    33  0   1   1   0   1   1   0   0   7   4   5   8   8   5   6   7

For example the 0 in O1 corresponds to the 4 in S1. I want to make a loop that will sum all of the values corresponding to variable 0 and 1.

  • if value in O1 is 0, add value in S1 to "sum of 0"
  • if value in O1 is 1, add value in S1 to "sum of 1"
  • repeat for all columns to get a total value for 0 and 1.

Any strategies or tips would be helpful going forward!

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
JPB
  • 11
  • 2
  • So you want to plot O1 by S1. I think a heat map could work. https://www.r-graph-gallery.com/heatmap.html – André Oliveira Nov 20 '19 at 21:04
  • You can convert your data from wide to long format then check the correlation between `O` and `S` columns https://stackoverflow.com/questions/12466493/reshaping-multiple-sets-of-measurement-columns-wide-format-into-single-columns & https://stackoverflow.com/questions/37884946/melting-two-sets-of-columns-from-wide-to-long-form-using-reshape2 – Tung Nov 20 '19 at 23:30
  • Have you tried box plots or strip charts? If you data frame is called `dta`, `boxplot(S2~O2, dta)` or `stripchart(S2~O2, dta)`. Use dput() to share your data, not a printed list and give us some more information. – dcarlson Nov 20 '19 at 23:31

0 Answers0