10,285 questions
-2
votes
0
answers
43
views
How can I use a named vector with recode? [duplicate]
Suppose I have
df <- data.frame(name=c("Hello", "Hi", "GoodMorning"))
I would like to convert "GoodMorning" into "GoodEvening" (of course this is ...
1
vote
4
answers
181
views
How to coalesce using a function of other rows?
I have the following tibble:
eu_df <- structure( list( nuts_code = c( "PT17", "PT17", "PT17", "PT17", "PT17", "PT17", "PT17", &...
3
votes
7
answers
328
views
Combine columns of a list of dataframes with a custom function
Suppose I have a list of dataframes l. All dataframes are guaranteed to have the same shape and contain the same columns.
I would like to combine the columns of those dataframes with a column-specific ...
4
votes
4
answers
296
views
How to expand printing of tibble's nested data types (list columns)?
When printing a tibble, how do I print the cells with nested data types (in list columns)? Let's have a look at two examples:
1. call data type
b <- tibble(a = 1, prior = list(call("rnorm"...
2
votes
2
answers
118
views
Deducting values across a data frame based on condition
I am trying to deduct values across a data frame of elements.
structure(list(Date = structure(c(20095, 20095, 20095, 20095,
20123, 20123, 20123, 20123), class = "Date"), Type = c("Drip&...
0
votes
1
answer
114
views
In `dplyr` `filter`, how to parse conditions which are stored in string? [duplicate]
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 ...
0
votes
2
answers
83
views
How to keep or recover group names
Sometimes, in case report forms the almost-same entries are inserted on a certain day and for some patient.
I want to find similar, possibly misspelled comment, per patient and date. Finding the ...
9
votes
6
answers
358
views
Use R to visualize activities across 24 hours as a pi chart 'clock' or bar
For fun, I would like to track the time when a baby is sleeping or feeding over the course of 24 hours and then visualize this as a pi chart or polar chart so that it resembles a 24-hour clock. Every ...
3
votes
4
answers
178
views
Create a dataframe column containing a list of number whose length is determined by another column
I have a data frame of names, and each name has a count of individuals, e.g.
df = read.table(header=TRUE, text=
'name count
a 10
b 1
c 7
d 3')
> df
name count
1 a 10
2 b ...
0
votes
1
answer
101
views
Tidyverse pivot_wider specify data which is retained as rows [duplicate]
I have a recurring problem which I have been addressing using a messy approach of multiple passes of pivot_wider and rbinding the results together. This seems inelegant, does anyone have a single ...
2
votes
3
answers
108
views
dplyr: find if a column value is substring of any item in a fixed list and mutate value
I started with a simple example which works, but I don't know how to use within dplyr mutate
This works, I get "bcd-234":
library(tidyverse)
list = c("abc-123", 'bcd-234', 'cde-345'...
1
vote
2
answers
132
views
Why does spec() return NULL after subsetting a tibble? (And how do I avoid that?)
After reading in my data using read_csv() from readr, the command spec() returns "full column specification" for the resulting tibble:
> spec(steps)
cols(
duration = col_double(),
...
3
votes
2
answers
132
views
How can I pass column names through nested functions using `dplyr` in R?
I am trying to write a function that, using tidyverse tools, will load two CSVs, join them on some key column, and write the joined result to a CSV. I am passing in the names of the key columns as ...
1
vote
2
answers
100
views
Join two dataframes, group by the first keeping all its columns, summarize the second
I have two data.frames, nests, and nest_days, which contains more days for one nest. I want to do a join, and group by nests (i.e. group by the rows of the first data.frame). I want to keep all ...
8
votes
4
answers
714
views
How to count number of instances over a threshold value between two dates?
I have two data frames I am working with. The first contains information on a cohort of kids. These same kids have been measured multiple times on different days (uniqueID AD_1 indicates child AD ...
1
vote
1
answer
35
views
Joint Histogram and Boxplot Plot with Faceting
I want to visualize the distribution of a variable ('F3A7_1') by plotting a histogram, and right underneath it a boxplot (below the y-axis of the histogram or something). I also want to create this ...
2
votes
3
answers
88
views
set_names() returns "character" not "tbl_df, tbl, data.frame"
Unexpected output of set_names()
I'm trying to name a list of tibbles using set_names.
I expect the names to be "tbl_df, tbl, data.frame"
However, the result is "character".
Any ...
2
votes
1
answer
71
views
How can I use group_by and mutate to perform a subtraction calculation with specific groupings? Time 0 minus Time X for all groups [closed]
I have this dataframe:
mydf <- structure(list(Time = c("T0", "T3", "T3", "T0", "T3", "T3"),
Organism = c("BB", "BB&...
1
vote
2
answers
58
views
How to plot geom_bar without showing multiple lines
I am trying to do a bar plot, however, is printing multiple lines on each bar. I understand that I might have to aggregate but if I do I need to retain the original columns because I need to fill by ...
2
votes
2
answers
277
views
Handling larger than memory datasets in R
I'm working with 50 Parquet files (each file is of ~800MB with ~380000 rows and ~8 columns). I need to perform a grouped summarisation in R. Something like:
group_by(sample_id, gene1, gene2) %>%
...
1
vote
3
answers
85
views
Create multiple tables
I am using survey data and would like to create multiple cross tables with row percentages at once.
Below is some dummy data and the way I would create those tables individually. Where I get confused ...
4
votes
5
answers
164
views
Add a column in R based on other columns values [closed]
I'm relatively new to R. I have a table of data consisting of an id, plus 3 values.
library(dplyr)
df <- tibble(id=c(1, 2, 3),val_a = c(13,25,42), val_b = c(25,30,0), val_c = c(7,27,21))
df
# A ...
2
votes
1
answer
124
views
Conditionally overwrite cell text with gt::gt()
With {gt}, you can conditionally style cells based on the values in another column in your dataframe. Is there a way to conditionally overwrite the cell display values based on a different column? In ...
2
votes
2
answers
97
views
cleaner way to match observations using IDs in different columns
I am using mark-recapture data, with each individual having a PIT tag (Tag) and a genetic sample ID given at the first observation (ID), which is typically used as the ID for the individual (Unified....
1
vote
1
answer
49
views
parse dynamic case_when based on thresholds values
I'd like to know if there is a way to parse a dynamic case_when expression.
Let's take as an example a vector of of 3 thresholds :
thresholds = c(0.4, 0.6, 0.8)
Based on that, I would like to assign ...