Skip to content
RDocumentation: subset
  • AI Chat
  • Code
  • Report
  • Note that this notebook was automatically generated from an RDocumentation page. It depends on the package and the example code whether this code will run without errors. You may need to edit the code to make things work.

    if(!require('base')) {
        install.packages('base')
        library('base')
    }
    subset(airquality, Temp > 80, select = c(Ozone, Temp))
    subset(airquality, Day == 1, select = -Temp)
    subset(airquality, select = Ozone:Wind)
    
    with(airquality, subset(Ozone, Temp > 80))
    
    ## sometimes requiring a logical 'subset' argument is a nuisance
    nm <- rownames(state.x77)
    start_with_M <- nm %in% grep("^M", nm, value = TRUE)
    subset(state.x77, start_with_M, Illiteracy:Murder)
    # but in recent versions of R this can simply be
    subset(state.x77, grepl("^M", nm), Illiteracy:Murder)