[Solved] How to calculate a condition using dplyr?

As I understand it, you want a column that checks if the temperature deviates by 5 – 6 degrees (if the temp is greater than 10) and another column to check if it is differs by 7 degrees or more. The current code you are using seems to identify the coldwave values correctly, although is … Read more

[Solved] Multiples rows to one row in R [closed]

We can group by ‘A’, ‘B’ and select the first non-NA element across other columns library(dplyr) df1 %>% group_by(A, B) %>% summarise(across(everything(), ~ .[order(is.na(.))][1]), .groups=”drop”) -output # A tibble: 1 x 8 # A B C D E F G H # <chr> <chr> <int> <int> <int> <int> <int> <lgl> #1 time place 1 2 … Read more

[Solved] dplyr selecting observations with filter [duplicate]

You could use paste to create the full name and filter to subset on that new variable library(dplyr) filter(d,paste(NAME,SURNAME) %in% c(“Giovanni Bianchi”,”Luca Rossi”)) NAME SURNAME COLOR 1 Giovanni Bianchi Red 2 Giovanni Bianchi Blue 3 Luca Rossi Blue 4 Luca Rossi Red Data d <- read.table(text=” NAME SURNAME COLOR Giovanni Rossi Red Giovanni Bianchi Red … Read more

[Solved] Group data in one column based on a string value in another column using dplyr

You can filter the data based on the column, then do the count for task : df <- data.frame( student = c( rep(“A”, 4), rep(“B”, 4), rep(“C”, 4), rep(“D”, 4) ), task = rep( c(“Home”, “Class”, “Assign”, “Poster”), 4 ), res = sample( c(“Completed”, “Pending”, “Not performed”), 16, TRUE ) ) library(dplyr) #> #> Attaching … Read more

[Solved] combine duplicates, do not publish blanks, dplyr::distinct

Perhaps the reason that you are having problems is that you are using empty strings when you should be using NAs. This is what I would assume is the idiomatic code. df <- data.frame(unique_id = c(rep(1,3),rep(2,3)), school = c(rep(‘great’,3),rep(‘spring’,3)), subject = rep(c(“Math”, “English”, “History”),2), grade = c(88,78,98,65,72,84), sex = c(NA,NA, “male”, NA, “female”, NA)) r2 … Read more