Skip to main content

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.

tidyverse
0 votes
0 answers
26 views

How can I use a separate column value to choose how to fill in values using values_fn in pivot_wider? [duplicate]

I have a dataframe descriptions names cutoffs vals 1 a A 90 1 2 a A 91 2 3 a B 90 3 4 a C 90 4 that I ...
mintak's user avatar
  • 1
1 vote
2 answers
29 views

parallel/automatic way of unnesting list columns that contains data frames (list columns might be empty)

Please consider the following data frame: df <- structure(list(oID = c(37751L, 30978L, 33498L), peId = c(12L, 13L, 14L), last_Name = c("ABC", &...
deschen's user avatar
  • 10.4k
1 vote
1 answer
50 views

Little hack for ggplot -- an easy way to add a text with the real means and standard deviation when using lines or bars

I just want to add some text of real means and sd to my plots when I'm working with one outcome or multiple outcomes. see the pictures below for reference. Code is below. If any updated package ...
Luis's user avatar
  • 1,530
0 votes
0 answers
38 views

What is the preferred / recommended rlang metaprogramming syntax to use on both sides of an assignment operator in the `dplyr::mutate()` function?

I have a question about an issue that's similar to this older question about the dplyr::filter() function, except that my example is a bit more complicated because dplyr::mutate() needs to process ...
stachyra's user avatar
  • 4,553
1 vote
1 answer
22 views

Long to wide format based on variable suffixes in tidyverse in R

I wonder if there is a way for my DATA to be reformatted to my Desired_output below? Specifically, for each unique study, we stick together a pair of pre and postNUMBER together, separately for T and ...
Simon Harmel's user avatar
  • 1,449
1 vote
2 answers
51 views

Use ifelse for several columns in R

My goal is to create a binary variable (k) that turns 1 if in any column between mpg and wt the values 3.90 and/or 160.0 appears. Code library(tidyverse) mtcars<-mtcars%>% mutate(k=ifelse(mpg:...
Amc's user avatar
  • 151
0 votes
1 answer
19 views

Transforming value into row number

I am conducting some survival analysis and an attempting to turn my wide table into long format for analysis using dplyR. I want to turn the value of 'dead flies' into rows with a binary status for ...
Dan Pritchard's user avatar
0 votes
0 answers
23 views

How to color the legend labels in ggplot [duplicate]

Using the iris dataset, we can make a boxplot and customise the legend when plotting using ggplot like so: ggplot(data = iris, aes(x=Species, y=Sepal.Length, fill=Species))+ geom_boxplot()+ ...
Ginko-Mitten's user avatar
0 votes
1 answer
44 views

Is there a way to pass a string as a variable/column name to my function and use in a call to mutate?

I have a dataframe with a column indicating choices (of a survey) as well as a column indicating the index of the choice made in each row. e.g., df <- tibble( record_id = 1:9, choices = c(rep(&...
sometimes_sci's user avatar
0 votes
1 answer
25 views

`pivot_longer` with`names_transform` [closed]

All examples I can find of pivot_longer using names_transform, have the following pattern: df %>% pivot_longer( ... names_to = "x", names_transform = list(x = some_func) # ...
user615536's user avatar
4 votes
1 answer
54 views

Is there a way to prevent facet labels from being equal width (after rotation)

When I apply a facet_grid, sometimes the labels are quite wide, sometimes so wide that they don't fit, and I have to rotate them. This isn't a problem unless I want to facet by multiple different ...
Dan's user avatar
  • 284
0 votes
1 answer
68 views

How to iterate a function for multiple values (Loop function)?

By running the following function, the output would be: library(pmsampsize) pmsampsize(type = "s", csrsquared = 0.5, parameters = 10, rate = 0.065, timepoint = 2, meanfup = 2.07) NB: ...
elisa's user avatar
  • 5
0 votes
1 answer
43 views

Change raster extent with tidy

I have files from ERA5 that have extent from 0 to 360 (lon) and -90 to 90 (lat) Example: > era5_sr class : SpatRaster dimensions : 721, 1440, 744 (nrow, ncol, nlyr) resolution : 0.25, 0....
herakles_1950's user avatar
1 vote
2 answers
34 views

In R, how to find the proportion of cases which have a value present in another column?

This seemed really simple to me at first, but is unexpectedly giving me trouble. Let's say my dataset looked like this: mock <- tribble(~case_id, ~characteristic, 1, "A&...
daltoncito5034's user avatar
1 vote
2 answers
46 views

Divide groups in other groups by date intervals

I'm dealing with dates and I wanted to group some rows together but I can't find how. In my data, one row is an individual in a time interval and in a place. Something like that : ind place ...
jrdavalos's user avatar

15 30 50 per page
1
2 3 4 5
676