Hi, I have this dataset with unique Id variables in column A and then subsequent renal scans for each patient. It is a csv file and I want to reshape it to long format using R if possible. Each participant can have a number of renal scans ranging from 1-17.
Also some Id are listed as 'No' for not receiving scan. I want it to be reshaped to something similar to this
I know previous questions on this organize by year, I have scans from participants that occur multiple times during the year date format yyyy-mm-dd
Please see data below
structure(list(id = c(1010001, 1010002, 1010004, 1010005, 1010006,
1010007), `GFR Scans?` = c("Yes", "Yes", "Yes", "Yes", "Yes",
"No"), `1. Date of renal scan:` = structure(c(1133913600, 1196812800,
1237334400, 1124150400, 1192060800, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), `1. Type of renal scan:` = c("DTPA",
"DTPA", "DTPA", "DTPA", "DTPA", NA), `1. GFR mL/1.73 sq.m` = c(18,
13, 68, 117, 46, NA), `1. Pre/Post tx?` = c("Pre", "Pre", "Post",
"Post", "Pre", NA), `2. Date of renal scan:` = structure(c(1146528000,
1214524800, NA, 1151366400, 1245974400, NA), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), `2. Type of renal scan:` = c("DTPA",
"DTPA", NA, "DTPA", "DTPA", NA), `2. GFR mL/1.73 sq.m` = c(86,
110, NA, 148, 123, NA), `2. Pre/Post tx?` = c("Post", "Post",
NA, "Post", "Post", NA), `3. Date of renal scan:` = structure(c(NA,
1219104000, NA, 1184025600, NA, NA), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), `3. Type of renal scan:` = c(NA, "DTPA", NA,
"DTPA", NA, NA), `3. GFR mL/1.73 sq.m` = c(NA, 92, NA, 166, NA,
NA), `3. Pre/Post tx?` = c(NA, "Post", NA, "Post", NA, NA), `4. Date of renal scan:` = structure(c(NA,
1242691200, NA, 1213660800, NA, NA), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), `4. Type of renal scan:` = c(NA, "DTPA", NA,
"DTPA", NA, NA), `4. GFR mL/1.73 sq.m` = c(NA, 36, NA, 171, NA,
NA), `4. Pre/Post tx?` = c(NA, "Post", NA, "Post", NA, NA), `5. Date of renal scan:` = structure(c(NA,
NA, NA, 1288656000, NA, NA), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
`5. Type of renal scan:` = c(NA, NA, NA, "DTPA", NA, NA),
`5. GFR mL/1.73 sq.m` = c(NA, NA, NA, 105, NA, NA), `5. Pre/Post tx?` = c(NA,
NA, NA, "Post", NA, NA), `6. Date of renal scan:` = structure(c(NA,
NA, NA, 1323129600, NA, NA), class = c("POSIXct", "POSIXt"
), tzone = "UTC"), `6. Type of renal scan:` = c(NA, NA, NA,
"DTPA", NA, NA), `6. GFR mL/1.73 sq.m` = c(NA, NA, NA, 103,
NA, NA), `6. Pre/Post tx?` = c(NA, NA, NA, "Post", NA, NA
), `7. Date of renal scan:` = structure(c(NA, NA, NA, 1355184000,
NA, NA), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
`7. Type of renal scan:` = c(NA, NA, NA, "DTPA", NA, NA),
`7. GFR mL/1.73 sq.m` = c(NA, NA, NA, 98, NA, NA), `7. Pre/Post tx?` = c(NA,
NA, NA, "Post", NA, NA), `8. Date of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `8. Type of renal scan:` = c(NA, NA,
NA, NA, NA, NA), `8. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA,
NA, NA), `8. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA), `9. Date of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `9. Type of renal scan:` = c(NA, NA,
NA, NA, NA, NA), `9. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA,
NA, NA), `9. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA), `10. Date of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `10. Type of renal scan:` = c(NA, NA,
NA, NA, NA, NA), `10. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA,
NA, NA), `10. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA),
`11. Date of renal scan:` = c(NA, NA, NA, NA, NA, NA), `11. Type of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `11. GFR mL/1.73 sq.m` = c(NA, NA, NA,
NA, NA, NA), `11. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA
), `12. Date of renal scan:` = c(NA, NA, NA, NA, NA, NA),
`12. Type of renal scan:` = c(NA, NA, NA, NA, NA, NA), `12. GFR mL/1.73 sq.m` = c(NA,
NA, NA, NA, NA, NA), `12. Pre/Post tx?` = c(NA, NA, NA, NA,
NA, NA), `13. Date of renal scan:` = c(NA, NA, NA, NA, NA,
NA), `13. Type of renal scan:` = c(NA, NA, NA, NA, NA, NA
), `13. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA, NA, NA), `13. Pre/Post tx?` = c(NA,
NA, NA, NA, NA, NA), `14. Date of renal scan:` = c(NA, NA,
NA, NA, NA, NA), `14. Type of renal scan:` = c(NA, NA, NA,
NA, NA, NA), `14. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA, NA,
NA), `14. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA), `15. Date of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `15. Type of renal scan:` = c(NA, NA,
NA, NA, NA, NA), `15. GFR mL/1.73 sq.m` = c(NA, NA, NA, NA,
NA, NA), `15. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA),
`16. Date of renal scan:` = c(NA, NA, NA, NA, NA, NA), `16. Type of renal scan:` = c(NA,
NA, NA, NA, NA, NA), `16. GFR mL/1.73 sq.m` = c(NA, NA, NA,
NA, NA, NA), `16. Pre/Post tx?` = c(NA, NA, NA, NA, NA, NA
), `17. Date of renal scan:` = c(NA, NA, NA, NA, NA, NA),
`17. Type of renal scan:` = c(NA, NA, NA, NA, NA, NA), `17. GFR mL/1.73 sq.m` = c(NA,
NA, NA, NA, NA, NA), `17. Pre/Post tx?` = c(NA, NA, NA, NA,
NA, NA)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"))
The first image is the original wide format, second image is what I am trying to get. None of the other wide to long answers on this have helped me as I have multiple columns involved.
e.g. id 1010001 has had two scans, I need this listed one after each other and not beside each other (see image two).
I would really appreciate your help.