Get Subset from Data Frame

  • salary$id
    • is one way to access a variable inside the data frame
  • salary$id[1]
    • access first element of the vector
  • alary$id[2:3]
    • access a subset of elements
  • salary$id[c(5,7)]
    • access elements 5 and 7
  • salary$id[ salary$[salary$startyr == 95]
    • all people join in 95
  • salary[1,]
    • get the first row
  • salary[,2]
    • get the second column
  • salary[3:7, 2:4]
    • some rows and columns
  • salary[, c("id","temp")]
    • extract columns by name
  • yes = antibiotics[antibiotics$antib == 1, ]
    • put this subset into a new data frame

  • select variables
Data1 <-ID_ICD9_Date1st_count_v2018_1M_random[,c(2,5,7,10:18,21)]

survdata_run <- dplyr::select(Data_Analysis, 1,3:9,17)
  • random select records
Data1 <- Data1[sample(nrow(Data1), 50000), ]

Reference:

results matching ""

    No results matching ""