Creating a Dataframe

Sameer Mahur

Creating a dataframe

# creating a 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)
patientdata
  patientID age diabetes    status
1         1  25    Type1      Poor
2         2  34    Type2  Improved
3         3  28    Type1 Excellent
4         4  52    Type1      Poor

Creating a dataframe

patientdata[1:2]
  patientID age
1         1  25
2         2  34
3         3  28
4         4  52

Creating a dataframe

patientdata[c("diabetes","status")]
  diabetes    status
1    Type1      Poor
2    Type2  Improved
3    Type1 Excellent
4    Type1      Poor
patientdata$age                       
[1] 25 34 28 52