Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Accessing Columns in Data Frames | Section
Essential R Programming for Absolute Beginners - 1768563985826

bookAccessing Columns in Data Frames

Data frames always have named columns, and you can use these names to extract specific columns. There are two main approaches.

Using Square Brackets

You can specify the column name inside square brackets.

Example

1234567
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # Extracting the name with square brackets test[, "name"]
copy

Using the Dollar Sign

Data frames also support a shorthand operator, $, which allows you to access a column by name without quotes.

Example

1234567
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # Extracting the name with dollar sign test$name
copy
Tarea

Swipe to start coding

You have the mtcars dataset.

Your tasks are:

  1. Extract the cyl column values using square brackets.
  2. Extract the disp column values using the dollar $ sign.

Solución

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 36
single

single

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

close

bookAccessing Columns in Data Frames

Desliza para mostrar el menú

Data frames always have named columns, and you can use these names to extract specific columns. There are two main approaches.

Using Square Brackets

You can specify the column name inside square brackets.

Example

1234567
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # Extracting the name with square brackets test[, "name"]
copy

Using the Dollar Sign

Data frames also support a shorthand operator, $, which allows you to access a column by name without quotes.

Example

1234567
name <- c("Alex", "Julia", "Finn") age <- c(24, 43, 32) gender <- c("M", "F", "M") test <- data.frame(name, age, gender) # Extracting the name with dollar sign test$name
copy
Tarea

Swipe to start coding

You have the mtcars dataset.

Your tasks are:

  1. Extract the cyl column values using square brackets.
  2. Extract the disp column values using the dollar $ sign.

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 36
single

single

some-alt