Skip to main content
  1. About
  2. For Teams
Filter by
Sorted by
Tagged with
3 votes
2 answers
99 views

Replace NA values in R dataframe across multiple columns using truncated names of other columns [duplicate]

I have the following data frame (example): myfile <- data.frame(C1=c(1,3,4,5), C2=c(5,4,6,7), C3=c(0,1,3,2), C1_A=c(NA,NA,1,2), ...
JohnPat's user avatar
  • 75
4 votes
2 answers
79 views

mutate(across(map())): Any way to include the column name in a .progress message from map()?

If you want to call a function that returns multiple values on a column of a data.frame, and append these values as new columns to the data.frame, you can mutate(map()) |> unnest_wider(). If it's ...
mac's user avatar
  • 3,742
2 votes
1 answer
84 views

summarise(across(starts_with())) in R

I have a dataframe which has three years of observations per ID and an indicator showing whether the ID was above or below a threshold in each year much like this: library(dplyr) library(tidyr) set....
surdity's user avatar
  • 35
3 votes
3 answers
109 views

How to simplify across?

I have to use across() multiple times. Is there a way to simplify the following across() code? ori_df <- data.frame(base_1 = 1:3,base_2 = 7:9,base_3 =3:1, exp_1 =c(0.4,0.1,0.7),...
anderwyang's user avatar
  • 2,537
4 votes
3 answers
124 views

Calculate extra values for moving average (and other functions)

Suppose I have the following dataset: library(dplyr) library(zoo) df <- data.frame(date = seq.Date(from = "2025-01-01", to = "2025-01-10"), value = 1:10) df #&...
Marcus Nunes's user avatar
1 vote
1 answer
64 views

Can distinct in dplyr keep only columns that have single unique value?

I want to use distinct to collapse a data.frame based on distinct values of a column sample_id. I would like to only keep the columns that also have a single value for each distinct value of sample_id,...
epurdom's user avatar
  • 89
0 votes
1 answer
89 views

bigrquery & DBI Error: Syntax error: Unexpected string literal 'table_name'

There appears to be a change or error with the bigrquery package. To connect to bigquery using DBI and dplyr you previously needed to do the following, which I got from https://github.com/r-dbi/...
Jaskeil's user avatar
  • 1,271
0 votes
2 answers
157 views

How to mutate values in one dataframe from a different, summarised dataframe

I am attempting to blank correct some data, but I need to do so in a specific order. To do this, I need to find the average blank measurement for a given time-point, and then subtract it from every ...
Jack_L's user avatar
  • 25
6 votes
5 answers
188 views

Referencing a vector of values from other columns within dplyr::case_when()

I am using dplyr::case_when() to create a new column based on other columns of my dataframe. One of the cases is when a subset of the other columns are NA, then my new column is also NA. Here is a ...
JLinsta's user avatar
  • 171
4 votes
4 answers
141 views

Assign top 2 ranking by group

I am trying to assign a ranking across a group, and apply the ranking across the whole group My data look like this: colour <- rep(c("blue", "red"), 3) day <- rep(c("mon&...
Gilrob's user avatar
  • 135
2 votes
1 answer
70 views

How can we add all-zero rows and columns in a table made by tbl_hierarchical?

let's just say that I have a table template, and I need to populate all the groups and values regardless of the analysis data, all-zero row or columns, I tried this way: library(gtsummary) ...
Huan Lu's user avatar
  • 109
6 votes
5 answers
477 views

Conditional counting based on multiple conditions

I have a tidy ecological dataset in which every row is a single specimen/individual, with multiple columns for multiple variables. #fake dataset loc <- c(1,1,2,2,2,3,3,3,3,3,3,3,3) date <- c(...
matteo_rpm's user avatar
0 votes
0 answers
55 views

Dplyr select top n% of a dataframe by column value [duplicate]

I am trying to filter this toy dataframe dat to remove the bottom 10% of num, and am trying to adapt the code from this source in a simpler format for my needs. I have 1:10 in num, so I would like to ...
cfausto's user avatar
  • 75
1 vote
1 answer
84 views

Estimate time spent in each cycle occurence of a factor variable [closed]

Temperature is meaesured in each two minutes and temperatures between 2.0 and 7.9 are fine, 8.0 and above are hot, 0.0 and 1.9 are cold, and minus zero is too cold. I want to measure time in each ...
Erdem Erkoyun's user avatar
5 votes
3 answers
237 views

Efficiently group rows within tolerance for multiple numeric columns

I'm trying to group rows that have values within specific error/tolerance. Input looks like this: input <- data.frame(Row_number = 1:22, Name = c(rep("A",6), rep("...
Jennifer's user avatar
  • 317

15 30 50 per page
1
2 3 4 5
2510
Morty Proxy This is a proxified and sanitized view of the page, visit original site.