-1

I am going to do repeated measures ANOVA on my data, but to this point, my data is wide. Two independent (categorical) variables are spread across single responsive variable. See the image: https://i.stack.imgur.com/0trSM.jpg I want to create two categorical variables that take values from the different parts of the columns (circled on the screenshot). Subject numbers should be kept as a category. So after using gather() function, the data should look something like this:

https://i.stack.imgur.com/Og6Gb.jpg

I've seen in a tutorial (that I can't find anymore) that you can create two columns from a single function, using different parts of the colnames (using "_" as a separator), but I can't exactly remember how it was done.

Any help would be appreciated and ask if anythings is not clear in my explanation.

irakli
  • 1
  • 1
  • 1
    This is at the top of the R tag questions in SO: Please provide minimal and reproducible example(s) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. Do not embed pictures for data or code, use indented code blocks instead. – G. Grothendieck Jun 04 '19 at 22:11
  • There are several functions that will separate columns the way you describe. One is `tidyr::separate` – camille Jun 05 '19 at 00:39

1 Answers1

0

I have solved the problem by using 'gather()' function first and then 'separate()' to separate it into two new columns. So I guess, if you want to make two key columns, first you have to make a single column containing both values and later separate it into two. At least that is how I did it.

irakli
  • 1
  • 1