Category "dplyr"

How can I use a vector variable to avoid repeating references to non-adjacent columns in R?

Question In R, can I used a vector that holds the names of data frame columns to avoid repeated code? vec_columns <- c("col1", "col2", "col8", "col54") Bac

str_detect removing some but not all strings with specified ending

I'd like to remove any string that ends in either of 2 characters in a pipe. In this example it's ".o" or ".t". Some of them get removed, but not all of them, a

Problem with `mutate()` input `index_date` when performing time series xgboost in R

here my reproducible example mydat=structure(list(supplier = c("TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP", "TKP",

Using Dplyr to calculate percent by group for every column without specifying the name?

This is similar to this. However what I'm interested is to calculate the percentage for every column. So for example when I do the below I can calculate column

How to remove pairs of rows corresponding to same value in R dataframe?

For the unique pair of ID, if both corresponding rows are 0, I need to remove them. In this case, remove row #5 and #6 but not row #7 and #8. tmt.pair <- c("

Organize columns with numerical info in colnames via dplyr relocate

I have a large amount of annual data in a data frame that will only get larger. I would like to organize it, grouping columns according to the year, which is

Multiply columns in dataframe by values given in another dataframe

I've been trying to accomplish this in dplyr but not been able to figure it out. In one data frame (df1) I have columns with values. |A |B | |23 |43 | |24 |11

How to count unique entries in a column across multiple columns in R

I have a data set that looks something like this data set example I am trying to find unique entries in each of the columns I managed to do it for 1 column util

How do you populate missing dates for lag?

Say that I have a dataset. date <- c("2004-02-01", "2004-03-05", "2004-08-09", "2004-08-13", "2004-10-20", "2004-11-02", "2008-01-05", "2008-02-03", "2008-08

In a dashboard made with R, how can I filter/unfilter based on selectInput?

I have created a simple dashboard (link here) to display some data in R using selectInput. How can I activate/deactivate a filter reactively, so that the output

Extracting rows based on more than two partial strings that must all be part of the string

I want to extract rows that must contain two or more partial strings. For example, suppose I have the following data.table df <- data.table(player = c('A', '

Create a column includes all confidence intervals

I have a code like that : library("survival") library("survminer") data("lung") res.cox <- coxph(Surv(time, status) ~ sex, data = lung) x<-confint(res.

How do I populate upper.tri of matrix with matched integers from the lower.tri?

Issue I have a dataframe of familial relationships coded with integers, where R01 is the relationship of person N to person 1, R02 their relationship to person

How can I find the nearest date after another date in a different column in grouping by ID using R?

I am looking for a method that will look at each date in "Date A" and find the next nearest date after that value in "Date B" by ID (group_by). I then want to c

dplyr mutate only works once

I'd like to add a new variable to a dataframe for plotting labels, as seen in the top voted answer here Here's the data: small <- structure(list(Site = stru

How could I bar_plot this data.frame?

vertejumi_ceturksnos <- data.frame( Vertejumi = c("0", "1", "2", "3"), Pirmais = c(Pirmaiss), Otrais = c(Otraiss), Tresais = c(Tresaiss), Ce

Creating custom Quantiles within data frame?

If i have the following table: tibble(year = c("2020", "2020", "2020","2021", "2021", "2021"), website = c("facebook", "google", "youtube","facebook", "

How to convert timestamp to date in each row of a column in R?

I have a column which list timestamps and I am in need of converting that to corresponding date for all rows in that column. Listing the code below app21_csv &

%>% .$column_name equivalent for R base pipe |>

I frequently use the dplyr piping to get a column from a tibble into a vector as below iris %>% .$Sepal.Length iris %>% .$Sepal.Length %>% cut(5) How

Using R to Calculate the time since binary output=1

I have binary data in a dataframe with a time feature and I'm looking to produce a dataframe like below with a new column "duration since =1". I was able to fi