Merging and/or spreading several columns

Hi! I've just started a new job where RStudio is the sole statistical package used (I've learned SPSS and Stata), and I need help on a crucial operation. Maybe the answer is readily available on Google, and I'll apologise beforehand then, but I'm simply not familiar enough with this language.

I have a large dataset of blood samples where each row corresponds to an individual sample. Each row has a unique sample number, and the same patient may thus have data on several rows if several blood samples were taken.

Unique values for each patient is socsecnum (social security number), sex, age and name. Now, what I'd like to do is have one row for each patient containing those unique values AND the remaining values on multiple columns, as seen here:

So a new variable is created for each individual blood sample as well as the time and bacterium values corresponding to that sample. How do I do this?

Thank you in advance!

Take a look at tidyr (https://tidyr.tidyverse.org)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.