Question: Write the R code needed to convert a data frame that looks like this: table [ [ , grp , sex,meanL,sdL , meanR,sdR ]
Write the R code needed to convert a data frame that looks like this:
tablegrpsex,meanL,sdLmeanR,sdRAFAMBFBM
into a data frame that looks like this:
tablegrpFmeanL,FmeanR,FsdLFsdRMmeanL,MmeanR,MsdLMsdRAB
Hint: You will need to use pivotlonger unite and pivotwider
The unite function is the inverse of separate it combines multiple columns into a single column. By default, unite will place an underscore between the values from different columns; if you prefer to use a different string say a period, hint hint provide that string as the sep argument.
I recommend you manually recreate the original data frame above using the data. frame function so that you can test your solution. I have given many examples of how to manually create data frames in my lecture examples, so you can review the lecture code files if you are unsure how to do this.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
