Questions tagged [tidyverse]

ONLY use this tag if your question relates to the installation, integration with your system, or inclusion of the entire tidyverse library. DO NOT USE if your question relates to one or two components of the tidyverse, such as dplyr or ggplot2. Use *those* tags, and tag with `r` as well for a better response.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

I am having trouble installing tidyverse packages in Posit Cloud. ‘lib’ is unspecified error [closed]

install.packages("tidyverse")` Installing package into ‘/cloud/lib/x86_64-pc-linux-gnu-library/4.3’ (as ‘lib’ is unspecified) trying URL 'http://rspm/default/__linux__/focal/latest/src/...
Anthony's user avatar
3 votes
1 answer
35 views

Count value coincidences into the same group

Say we have this DF: id city 1 Swindon 1 Malmesbury 1 Kettering 2 Bath 2 Swindon 2 Salisbury 2 Kettering 3 Swindon 3 Kettering 3 Bath ...
teogj's user avatar
  • 321
1 vote
0 answers
47 views

How to Set Names for Nested Lists in R of Depth 5

I'm working with a deeply nested list structure in R, and I'm having trouble setting names for lists at a depth of 5. I've managed to do it for lists of depth 4, but I'm unsure how to proceed further. ...
Xavier's user avatar
  • 11
0 votes
2 answers
45 views

How to use !!sym when performing a shapiro_test on a dataframe undergoing a for loop?

I am trying to loop through a dataframe and run both statistical summaries, tests and graph a plot by looping through certain columns within the dataframe. I am new to for loops in r, and sort of ...
JLit98's user avatar
  • 17
0 votes
1 answer
15 views

Find Overlap in Dates Between Multiple Date Columns in the Same DF

I have a df as below where each column (v1-v10) is a unique set of dates from 10 other data frames containing various data. I want to find the date range/ranges in which all columns (v1-v10) share. ...
Eizy's user avatar
  • 273
0 votes
1 answer
38 views

The rep function calculating mean and standard deviation

This is my sample data: x1 <- c(1, 2, 3, 4, 5) x2 <- c(6, 7, 4, 5, 7) x3 <- c(4, 5, 3, 7, 1) x4 <- c(3, 5, 6, 4, 2) x5 <- c(1, 3, 4, 4, 2) x6 <- c(4, 5, 4, 3, 5) df <- data.frame(...
Gato's user avatar
  • 417
1 vote
1 answer
32 views

Is it possible to use add_row function within group_modify function multiple time?

The sample dataset is as below: a = data.frame(a = as.factor(c(1:3)),b = c(1:3), c = c('q','g','k')) I would like to add two row to the dataset according to a : a b c 1 1 'q' 1 2 'd' 1 9 't' 2 2 ...
doraemon's user avatar
  • 453
0 votes
1 answer
23 views

How to fix ordering of the sankey diagramm when using R ggalluvial, ggsankey package?

Here is the input datasets: id <- c("A1", "A2", "A3", "A4", "A5", "A6", "A7", "A8", "A9", "A10") ...
choij's user avatar
  • 233
0 votes
1 answer
23 views

R: How to add range of defined strings inside string containing variable?

Here is the example datasets: id <- c("aaa1", "aaa1", "bbb1", "aaa2", "b1","a3", "a1", "b1", "a1", "b1&...
choij's user avatar
  • 233
0 votes
0 answers
30 views

Getting missing values into a tibble [closed]

Can you spot an error in this code? For some reason I get NAs for Sumvar2_mean_of_means and Sumvar2_stddev_of_mean_of_means. Regarding the sumvar1 everything works. df %>% ungroup() %>% ...
Gato's user avatar
  • 417
0 votes
0 answers
11 views

How to add points of each group in ggplot to the boxplot [duplicate]

I have data that I need to make clustered boxplot for, here is a sample: data = structure(list(Cluster = c("1 Cluster", "3 Clusters", "5 Clusters", "4 Clusters"...
Mustafa Kamal's user avatar
0 votes
1 answer
28 views

R: How to add custom character inside string depends on the group?

How to add custom character inside string containing variable depends on the group variable? Here is the dummy input dataset: library(tidyverse) unit <- c(50, 50, 40, 40, 30, 30, 20, 20, 10, 10) ...
choij's user avatar
  • 233
0 votes
1 answer
27 views

Group by date then summarize and transpose data

I have a data set that looks like this: Date hh00 hh01 hh02 hh03 hh04 hh05 2021-09-01 21 0 51 12 65 96 2021-09-01 0 13 12 34 65 34 2021-09-03 12 0 0 1 61 96 2021-09-03 45 12 51 12 11 0 2021-09-...
Ryan Gary's user avatar
0 votes
2 answers
32 views

creating combinations in a dataframe in R

In R, I have a dataframe defined by foo <- data.frame(variable = c("peltrawl_PF","peltrawl_DF"),low = c(0,3.8),high = c(10,11)) I want to make it look like the dataframe bar &...
Fish_Person's user avatar
1 vote
2 answers
27 views

R wrangling model summary into tidy object

This is regarding , how to coerce a non tidy object into tidy universe. I am using a relatively new r package GLMMadaptive to fit a mixed model. This is the code Step1 : Creating the dataset set.seed(...
Science11's user avatar
  • 834
1 vote
0 answers
37 views

working with two sets of variables in dplyr

Let's suppose I have a df with two sets of variables, A and B. I want to work column-wise by substituting column B1 with A1 and column B2 with A2: library(dplyr) df <- data.frame( A1 = c(1, 2, 3)...
filemonPi's user avatar
0 votes
0 answers
18 views

Re-arrange columns within R dataframe matching with column name [duplicate]

In an R dataframe named 'df,' we have multiple columns with similar names, distinguished only by the suffix '_CA_NAME.' For example, there might be columns like "List of product" and "...
Sophia Wilson's user avatar
0 votes
0 answers
33 views

Cannot install R packages

Hi I have a problem installing any package in RStudio. The error I get: Error in download.file(url, destfile, method, mode = "wb", ...) : cannot open URL 'http://cran.ma.imperial.ac.uk/bin/...
mirko_sz's user avatar
2 votes
2 answers
45 views

Select common rows across different years

I have a very large dataframe containing 150,000 rows and 1,000 ID values, across 20 years. I want to keep all the rows that have common ID value across different years. x <- structure(list(ID = c(...
user27808's user avatar
  • 121
0 votes
1 answer
24 views

Label levels of a character variable in r

I want to create a new variable with labels of a character variable in a preceding column such that 6 = "6) Hazardous", 5 = 5) Very unhealthy", 4 = 4) Unhealthy etc I have tried other ...
Reuben Newton Addison's user avatar
0 votes
2 answers
19 views

How to add "swab" to text string when "dry0" occurs in R

I have a column with swab IDs. The normal ID nomenclature is "dryswab00001". However there are some samples as "dry00135". How would I str_detect those IDs and insert "swab&...
Eizy's user avatar
  • 273
-1 votes
1 answer
195 views

How to merge separate lapply and enable pivot_long column reading

I am performing the same operation through separated list of dataset library(glue) x1 = c('mpg', 'cyl') x2 = c('Month', 'Ozone') list_x = list(x1, x2) ...
12666727b9's user avatar
  • 1,067
0 votes
1 answer
36 views

pivot_longer two set of columns in R

library(tidyverse) df <- data.frame(names = c("John", "Peter", "Mary", "Allan", "Anne"), year = 2001:2005, ...
always.learning's user avatar
1 vote
1 answer
40 views

Is there anyway to name the columns of dataframe by using pipeline operator? [duplicate]

Sample dataset is as below: a = data.frame(c(1:3), c(4:6)) #a %>% `names <-` ('w', 'q') #The code did not work... If I want to rename the columns as 'w' and 'q', what should I do to get the ...
doraemon's user avatar
  • 453
2 votes
1 answer
25 views

How to add percents next to a column value

I have a large dataframe but this is a small subsample of it. I am trying to add a percent of each value right next to the daily value of each of my columns but in this case for only column 'F'. I am ...
Salvador's user avatar
  • 1,349
0 votes
1 answer
23 views

R: tidy_add_n() doesn't work when looping over many columns for Cox models with reformulate/as.formula

I would like to run a loop for Cox models that adjust for different subsets of covariates. The desired output should include number of events, person-years, hazards ratios, and 95%CI. If I call coxph ...
trinhtran's user avatar
0 votes
2 answers
28 views

Creating a dataframe with the counts of unique values from a different dataframe

I have a dataframe that contains multiple columns with different values between 0 and 1. e.g. > DF column1 column2 column3 column4 1 0 0 0.5 1 2 0.5 0.5 0.5 ...
Anders Jørgensen's user avatar
1 vote
1 answer
36 views

gt Table not being displayed on shiny app

I am working on a shiny app for a job application and I don't understand what I am doing wrong. I managed to display this table on a tab panel inside the main panel: prestamos_complete %>% ...
Emiliano Barone's user avatar
2 votes
1 answer
34 views

Creating Indicator from Index Date in R

I have a dataframe structured like this df <- tribble( ~pat, ~drug, ~`2023-01-01`, ~`2023-01-02`, ~`2023-01-03`, ~`2023-01-04`, ~`2023-01-05`, "1", "tylenol", 3, 0, 0, 1, 0,...
wdefreit's user avatar
0 votes
2 answers
31 views

R create a subgroup sequential index based on sorted dataframe criteria

I am trying to make a subgroup index column in a sorted data.frame that increments the index based on when a condition occurs. Consider the example from dput below which is a sf dataframe of points, ...
DarwinsBeard's user avatar
0 votes
0 answers
35 views

`geom_col()` renders x-axis scale (minimum wage data) incorrectly

I want to plot minimum wage data by state and year in a bar chart similar to this plot in wikipedia The data I used can be found here. The following code block should render the desired output but the ...
ptr64's user avatar
  • 102
1 vote
1 answer
17 views

Reorder matrix rows and columns based on alphabetical order of colnames and rownames in R

I was wondering if there is a way to reorder the rows and columns of the MATRIX below by their rownames and colnames in alphabetical order? MATRIX <- structure(c(0.00096, 0.00047, -0.00027, -0....
Simon Harmel's user avatar
  • 1,029
0 votes
1 answer
39 views

Remove part of string in one column based on overlap with another column (context-dependent)

I have the following data where everything is a string: Column A Column B "Do you like banana splits?" "Do you like banana splits? Yes, I do" "I am John" "I am ...
user22571454's user avatar
0 votes
1 answer
19 views

How to format numbers (comma) on a gt table

I have a gt table similar to the one in the example below. Some of the summary_rows and grand_summary_rows are comma formatted but others are not. Question: how can I format the entire gt table so ...
Salvador's user avatar
  • 1,349
1 vote
1 answer
20 views

How to Extract Time Interval Information from a tsibble Object in R?

I have a tsibble object in R and I would like to extract the time interval information (e.g., "7W") from it. Here's a simplified example: library(tsibble) df_weekly <- tsibble(tibble( ...
manuzambo's user avatar
  • 201
0 votes
3 answers
46 views

tidy - fill NA in columns with value two cells above the "NA" cells

I have a tidy dataset with an slightly unusual structure in some columns. The data structure is outlined in an example below - there is a header row containing all the key information, with records ...
lyd-m's user avatar
  • 3
-1 votes
2 answers
63 views

Stop tidyverse from renaming column in lapply

When I use group_by(col) inside lapply(), columns a and b are renamed to get(col). How do I stop this from happening? I would like to keep the original column names in the new objects. MRE Input df &...
myusername's user avatar
-1 votes
0 answers
15 views

Cannot subset character string with parantheses [duplicate]

I have a dataset with the entry "Banana (ripe)" and I want to get rid of the "(ripe)" part of the string. However, when I run the following code, the output is "Banana ().&...
Kansas Keeton's user avatar
3 votes
2 answers
100 views

Convert R data frame to json with different depths

I converted some nested json files (used by i18n translation system) to csv to allow non-IT colleagues to review the language without handling directly with the json files. Therefore, then I have to ...
Josep Pueyo's user avatar
-1 votes
0 answers
18 views

Problem with filling missing values in weekly data

I have weekly data in the yearweek format: "2015 W52", "2015 W53", "2016 W01". This data is already in tsibble format. #First: I selected the period train <- IAV2020%&...
Daniel Moraes's user avatar
2 votes
1 answer
25 views

How to add variables, make the it as equally dataframe

There is dataframe raw_data_2 , I want to add variables e_2022 b_2023,the result as dataframe raw_data_2_fixed .How to add them by easy code ? (In actual, i have to add so many variables, type in one ...
anderwyang's user avatar
  • 1,863
0 votes
0 answers
16 views

Fit arima model after joining W52 and W53. What to do with 53rd week of the year in R?

I am trying to forecast some weekly data in a tsibble format with train data from 2013 to 2016. In 2015, I have year week W53 with NA. Results with W53 and NA: Then, I join W52 and W53: join yearweek ...
Daniel Moraes's user avatar
0 votes
0 answers
20 views

Forecasting weekly data with ARIMA and tsibble for year with 53 weeks

I am trying to forecast some weekly data in a tsibble format with train data from 2013 to 2016. In 2015, I have year week W53 with NA. Results with W53 and NA Then, I join W52 and W53: join yearweek ...
Daniel Moraes's user avatar
2 votes
1 answer
35 views

How to add an external calculation to summary_rows fns = list(fn)

Could someone help me with adding another row to gt? I would like to add a row right below the Total. It seems like gt doesn't allow it because the call to gt() has been already made above. Data and ...
Salvador's user avatar
  • 1,349
1 vote
1 answer
35 views

replacing reshape2::decast() with tidyverse or R base

I was wondering if there is an equivalent for reshape2::dcast from tidyverse or even Base R in my code below to produce the same output below? library(reshape2) dat=structure(list(row = c("L2DA&...
Simon Harmel's user avatar
  • 1,029
2 votes
1 answer
24 views

Mean() not working with functions as arguments within a pie

I'm a beginner with R. I'm doing some exercises on data manipulation with dplyr, and I'm encountering something I don't quite understand. I'm with an exercise which uses the 'titanic' training dataset ...
Xavier Villà Aguilar's user avatar
0 votes
2 answers
46 views

Implement round using bind_rows(summarise)

I am trying to round values on my table summary but round gets applied to the entire table instead of one section. How can I apply round() to just my summarized last row of the table? round() appears ...
Salvador's user avatar
  • 1,349
1 vote
1 answer
33 views

Is there a generic way to add secondary axis in ggplot without scaling?

I want to have lines for the MAPE and Accuracy on the same plot using ggplot to see how they change over different clusters. I tried different solutions like this post, however, they do not work. Here ...
Mustafa Kamal's user avatar
1 vote
1 answer
21 views

How to remove the last "-" in a text string when a number follows it

I have multiple text columns with IDs. I want to remove the "-" only if it is the last one and the following character is a number. Please show tidyverse syntax as I will be mutating across ...
Eizy's user avatar
  • 273
1 vote
2 answers
28 views

Match when pivoting longer

I have the following dataset and I want to pivot part_c_name_1 and part_c_name_2 by one side and then, harvest_1 and harvest_2. When I try to do this with pivot_longer it does not understand that ...
Paula's user avatar
  • 567

1
2 3 4 5
196