Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Logical Indexing | Section
Essential R Programming for Absolute Beginners - 1768563985826

bookLogical Indexing

Logical indexing allows you to filter rows of a data frame based on conditions. Instead of remembering row numbers, you specify logical expressions, and only rows where the condition is TRUE are returned.

Example

123456789
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # People older than 30 test[test$age > 30, ] # Males only test[test$gender == 'M', ]
copy

The condition should be placed in the row index position inside square brackets ([condition, ]).

Opgave

Swipe to start coding

Using the mtcars dataset, extract the following data:

  1. The cars that pass a quarter-mile in less than 16 seconds (qsec column).
  2. Cars with 6 cylinders (cyl column).

Løsning

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 37
single

single

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

close

bookLogical Indexing

Stryg for at vise menuen

Logical indexing allows you to filter rows of a data frame based on conditions. Instead of remembering row numbers, you specify logical expressions, and only rows where the condition is TRUE are returned.

Example

123456789
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # People older than 30 test[test$age > 30, ] # Males only test[test$gender == 'M', ]
copy

The condition should be placed in the row index position inside square brackets ([condition, ]).

Opgave

Swipe to start coding

Using the mtcars dataset, extract the following data:

  1. The cars that pass a quarter-mile in less than 16 seconds (qsec column).
  2. Cars with 6 cylinders (cyl column).

Løsning

Switch to desktopSkift til skrivebord for at øve i den virkelige verdenFortsæt der, hvor du er, med en af nedenstående muligheder
Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 1. Kapitel 37
single

single

some-alt