I have a big dataset and have data in long format (‘longdf’) with one column for subjectnr., one for illness (e.g., rows are epilepsy, ms, diabetes etc.) and other columns for the variables (sociability, morality, competence, several stigma dimensions).
I need to do three dimensional PCA , so I need the data in wide format, but cannot loose the nested illness-structure (if you know what I mean). How to change this to wide format in R ?
I would really appreciate your help, also if you know something about a threedimensional PCA code.
Thanks 🙂
subject nr | illness | Sociability | Morality | Competence | Stigma Dimension 1 (other columns 2,3 etc) |
---|---|---|---|---|---|
1 | epilepsy | 2 | 1 | 3 | 1 |
1 | ms | 3 | 4 | 2 | 5 |
I tried it with a chatgpt code but it didnt work because of the nested data structure and I didnt understand what to make to names_to and values_to.