Hi!
I am sure there is a pretty simple way to do this but can not figure it out. My data is a csv file with header (patient id; time to relapse (months); time to transformation (in months). One row/patient. Lymphoma cohort.
I want to create a swimmer plot where one can see relapse and/or transformation.
I need to transform data to this format, eg
ID Response Time (months) 1. Relapse. 10 1 Relapse. 17 1 Transf. 25 1 Censored 56
I only need the ”start” time of relapse and/or transformation. I have seen the swimmer plot tutorial, so as long as I can create this format I will be able to create the plot.
It is not entirely clear for me what you want to do. So if I understand correctly, what you have is the following :
can you please post another clear example of what you want the data to look like after transforming?
sorry, I was very unclear.
So, in my "raw" file I have columns: ID, State1 (relapse/transformation), Time1 (time in months from diagnosis to State1), State2 (relapse / transformation), Time2 (time from diagnosis in months to State 2), State3 (death/ censored), Time3 (time from diagnosis to censoring / death), Status (dead / censored at last follow-up), OS (time from diagnosis to last follow-up or death)
I want to merge the State columns together for each patient in one column, same for Time
The end result would be 3 column: ID, State, Time
I dont know no how to post e.g. data frame example but e.g. Patient_ID1 would have State1 = Relapse Time1 = 10, State2 = Transformation, Time2 = 20, State3 = Death Time3=40 on so on for other patients
this is also not super informative, sorry. Roughly speaking - you have 3 columns (for state and time) and you want to merge them into one? and then delete the individual 3 columns?
I will make an attempt, lets say your data is in data frame
patient_data
and you want to perform the operations on columnsstate_1
,state_2
&state_3
andtime_1
,time_2
&time_3
and merge them into columnstate
andtime
, then you can do :Sources: 1) for combining columns - https://stackoverflow.com/questions/18115550/combine-two-or-more-columns-in-a-dataframe-into-a-new-column-with-a-new-name 2) for splicing certain columns in dataframe - https://stackoverflow.com/questions/10085806/extracting-specific-columns-from-a-data-frame
Thank you for this! I actually figured it out on my own and my swimmer plot look fine now :) I just did not (do not) know how to post questions so that one can see it like R dataframe
Instead of all those textual descriptions please simply provide representative inout and desired output examples.
I would if I only knew how...sorry, beginner.