0

i need to create a list of vectors from my dataframe 'patientdata' in the next way: for the first element of list: a vector of age of patients of Type1, for the second element of list: a vector of age of patients of Type2

Note that this is only a part of my big dataframe, in the real dataframe there is much more Type (Type3, Type4, ...). So the list need to be greater than 2 as i asked above, it depends of the number of Type.

here my dataframe:

patientID <- c(1, 2, 3, 4)
age <- c(25, 34, 28, 52)
diabetes <- c("Type1", "Type2", "Type1", "Type1")
status <- c("Poor", "Improved", "Excellent", "Poor")
patientdata <- data.frame(patientID, age, diabetes, status)

can someone help me please ?

Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
Sharon S
  • 15
  • 1
  • 5
  • 1
    If you are interested only in `age` you can use `split(patientdata$age, patientdata$diabetes)` or `split(patientdata, patientdata$diabetes)` to get complete data? Is this what you want? – Ronak Shah Jun 07 '20 at 09:56
  • thank you very much, is that what i wanted – Sharon S Jun 07 '20 at 10:03

0 Answers0