Skip to main content
Filter by
Sorted by
Tagged with
4 votes
2 answers
119 views

I am trying to set up a conditional argument in a function to drop columns from the tibble based on column name. There are a large number of columns but many are adjacent to one another and I would ...
user2352714's user avatar
Advice
0 votes
5 replies
182 views

Below my clunky way to seek what I'm looking for, just to know if someone has a nicer, shorter method. Relatively concerned with performance. Ideally I'd try to avoid creating another object in the ...
tjebo's user avatar
  • 24.1k
-1 votes
0 answers
48 views

I am trying to compare rows in a dataset and return a vector of all values that are NA in Row X but filled in Row Y. To do this I am reshaping the data using reshape2::melt and pivot_wider following ...
user2352714's user avatar
3 votes
4 answers
165 views

Below is a data frame that is grouped by the id variable. Variable x takes on values from 0 to 2. id<- c(1,1,1,2,2,3,3,4,4,4,4,4,4) x <- c(2,2,0,0,0,1,2,1,1,1,0,2,1) df <- data.frame(id, x) ...
T Richard's user avatar
  • 707
1 vote
2 answers
111 views

I want to make a new column like in column B in R Studio. but its keep like column C image example case for my case If in excel the function is I4 = IF(ABS(H4-H3)<0.1,I3+3600,3600). In RStudio ...
Ken Wiralino's user avatar
0 votes
1 answer
91 views

I'm trying to left_join data2 to data1, so that I end up with data3 data1 <- data.frame(ID = 1:4, Time = 0, X1 = c("a1", "a2", "...
JBL's user avatar
  • 49
0 votes
1 answer
115 views

I am new to R and trying to create two new variables from my dataset. My data frame is called netflix and it contains these relevant columns: date_added and duration Example values: date_added: "...
user31963479's user avatar
2 votes
1 answer
112 views

I have a data set of mark-recapture data with the fields species, ear_tag, pit_tag, and sample_id. I need to create a animal_id column so I can identify each unique animal which unfortunately has ...
Reed's user avatar
  • 340
1 vote
1 answer
229 views

TL;DR In short, how do I get ok.netroles <- c("netrole1", "netrole2"); mutate(across(ok.netroles)... to work like mutate(across(.cols=netrole1, netrole2, ...))? I am trying to ...
Stuart's user avatar
  • 661
5 votes
1 answer
108 views

With dplyr::rename I can rename columns if they exist: library(dplyr) df <- data.frame(a_old = 1:3, b_new = 11:13) lkp <- c(a_new = "a_old", b_new = "b_old") df %>% rename(...
thothal's user avatar
  • 20.7k
1 vote
2 answers
114 views

I currently have the below data frame: structure(list(cluster = c(2L, 3L, 5L, 5L, 6L, 6L, 7L, 9L, 9L, 10L, 10L), treatment = c("TreatmentA", "TreatmentA", "TreatmentA", ...
Megan Cole's user avatar
Tooling
1 vote
6 replies
335 views

I want to create a three layer pie chart using ggplot2 which requires that the data is arrange in certain way. This is the data I have: Level_1 Level_2 Level_3 Theme A Subtheme 1 A Theme A Subtheme 1 ...
Faisal Elvasador's user avatar
-2 votes
1 answer
107 views

I'm trying to use the filter function to remove values less than 10 from my dataset and create a new data frame, but I keep getting this error. The class of the data was originally integer but I used ...
Morgan Penner's user avatar
0 votes
1 answer
95 views

I have SPSS dataset, which has variables- name, sex, car_owned, where the value label of sex is "1= Male, 2 =Female" and car_owned is "1=BMW, 2=BYD, 3=Nissan". The SPSS dataset ...
studentcoder's user avatar
0 votes
1 answer
130 views

I want to add a seasonal_factor column to my D1 data frame. The seasonal factor is from another source, in matrix format, with 4 matrices per year from 2021 to 2024. I get errors on matching the same ...
Amy Z's user avatar
  • 11
1 vote
3 answers
204 views

I am predicting unknown values based on previous known values in a R dataframe: year pop datasource 2020 5999124 observation 2021 6017961 observation 2022 6036526 observation 2023 6054829 observation ...
Vesanen's user avatar
  • 453
4 votes
3 answers
204 views

I have a dataset with nine cities. I trained and tested four different machine learning models for each city. The results are in the tibble below: set.seed(1) result <- tibble::tibble(city = ...
Marcus Nunes's user avatar
3 votes
5 answers
206 views

I would like to do a check on my dataset to make sure a certain set of values are in every group and output a dataset showing all the values I am checking for and whether they exist in each group. How ...
user30397791's user avatar
4 votes
2 answers
164 views

Let's say I have a data.frame df: #fake dataset id <- c(1,2,3,4,5,6,7,8,9,10,11,12,13) loc <- c(1,1,2,2,2,3,3,3,3,3,3,3,3) date <- c(2021, 2022, 2021, 2021, 2022, 2021, 2021, 2022, 2023, 2023,...
sbj's user avatar
  • 41
3 votes
2 answers
242 views

library(lubridate) test <- data.frame(Location=c("A1","A1","A1","A1","A1","A2","A1","A1","A1","A1"...
Slayer25's user avatar
2 votes
1 answer
90 views

I'm having some issues trying to understand how to use expand and nesting in combination with tidyr::complete() to create a data frame where I fill in zeros for missing species. In short, while expand(...
jebyrnes's user avatar
  • 9,386
1 vote
2 answers
87 views

I'm trying to write a flexible grouping and summarizing function, with the interface f(data, group_vars, unit_vols) and struggling to inspect what's been passed to these data-masking arguments for ...
mac's user avatar
  • 3,794
0 votes
2 answers
84 views

I have a frequency table that I would like to reformat so that each row is for a single observation. For example, if my data looked like the following, I would like to have 10 rows where year = 1 and ...
tnt's user avatar
  • 1,527
4 votes
2 answers
145 views

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
  • 85
4 votes
2 answers
103 views

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,794
2 votes
1 answer
106 views

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
140 views

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,547
4 votes
3 answers
140 views

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
90 views

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
105 views

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
1 answer
166 views

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
221 views

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
161 views

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
107 views

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
  • 140
6 votes
5 answers
507 views

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
56 views

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
86 views

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
246 views

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
2 votes
1 answer
116 views

I have a data frame containing the specification for a set of regression models (regress_grid) with a column for different aspects of the model. I then use dplyr::rowwise() to estimate a model for ...
RichPatter's user avatar
1 vote
2 answers
90 views

library(dplyr) raw_data <- data.frame(cat=c("a"),char_1=c("1kg|2kg"),char_2 = c("0kg|1kg|8kg")) in raw_data how to mutate dif_char which values in char_2 and not in ...
anderwyang's user avatar
  • 2,547
0 votes
2 answers
126 views

I have a dataframe where I wish to generate an additional column with the value of the percent change calculated as the difference from the former row divided by the original value, then multiplied by ...
Matteo's user avatar
  • 537
8 votes
8 answers
1k views

I'm having trouble with the following in R using dplyr and separate. I have a dataframe like this: x<-c(1,2,12,31,123,2341) df<-data.frame(x) and I'd like to split each digit into its ...
Sointu's user avatar
  • 291
0 votes
1 answer
116 views

In dplyr filter, how to parse conditions which are stored in string?When there's only one condition, below code can work library(dplyr) conditions_string_1 <- "Species=='versicolor'" iris ...
anderwyang's user avatar
  • 2,547
0 votes
1 answer
76 views

I am trying to subset the data so that when I group by letter, I subset only for letters that have BOTH 'apple' and 'cherry' This is the code I have used but 'filtered_data' is showing empty. What am ...
Megan Cole's user avatar
3 votes
2 answers
123 views

Consider the data frame id <-c(1,1,1,2,2,3,3,3,3) x1 <-c("no","yes","yes","no","no","no","no","no","yes")...
T Richard's user avatar
  • 707
2 votes
3 answers
158 views

I'm working with pre/post assessment data. Each question has a score out of 5 and is collected at two timepoints for each student. library(tidyverse) name <- c("Student 1", "Student ...
golivia's user avatar
  • 23
3 votes
3 answers
163 views

I want to calculate the difference of the means of mutliple variables (e.g., size, weight) by categories (e.g., color, taste) and groups (e.g., fruit) in R. So I want to transform this fruit color ...
David's user avatar
  • 107
0 votes
2 answers
91 views

I have a dataset that has course completions from a variety of subject areas for a very large number of students. Each row of data is organized as follows: Student ID Gender City Course ETC. 10102 ...
Quinn McCashin's user avatar
0 votes
1 answer
59 views

(The last) follow up question: Adjusting values in a table based on another table, Splitting multiple values among multiple values I have these tables in R: myt_with_counts <- data.frame( name = c(...
stats_noob's user avatar
  • 6,855
0 votes
2 answers
72 views

This is a follow-up question: Adjusting values in a table based on another table I have two tables: myt_repeating <- data.frame( name = c("a", "a", "a", "b"...
stats_noob's user avatar
  • 6,855

1
2 3 4 5
754