Exploring Data with dplyr
Scorri per mostrare il menu
When you work with data frames in R, the dplyr package gives you a powerful set of tools for exploring and manipulating your data. The most important dplyr verbs are select, filter, arrange, mutate, and summarize. Each verb performs a specific type of operation:
select: choose specific columns from your data;filter: keep only rows that meet certain conditions;arrange: reorder rows based on column values;mutate: add new columns or transform existing ones;summarize: reduce your data to summary statistics.
These verbs allow you to quickly inspect and explore your data frames, making it easier to focus on the information that matters most.
12345678910111213141516library(dplyr) options(crayon.enabled = FALSE) # Create a sample tibble data <- tibble::tibble( name = c("Alice", "Bob", "Carol", "David"), age = c(25, 30, 22, 35), score = c(88, 92, 95, 85) ) # Use select and filter to subset the tibble result <- data %>% select(name, score) %>% filter(score > 90) print(result)
A key feature of dplyr is the pipe operator %>%, which lets you chain together multiple operations in a clear, readable sequence. Instead of nesting functions inside each other, you pass the result of one operation directly into the next. This approach makes your code easier to read and understand, especially as your data wrangling tasks become more complex.
Grazie per i tuoi commenti!
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione