tidyverse Questions
3
Solved
I have the following data:
df <- structure(list(id = c("1358792", "1358792", "333482", "333482", "747475", "747475"),
x = c("123...
2
Solved
This works as expected:
library(dplyr)
f <- function(x = c(am, vs))
mtcars %>%
select({{x}})
How would I rewrite the function (let's call it f2) such that f2 selects only the first elem...
Upswing asked 6/9 at 11:57
3
Solved
I have two tibbles with unique values, with unequal length like:
df1 <- structure(list(col1 = c("A", "T", "C", "D", "X", "F")), class ...
3
Solved
Say that I have this list:
listexample = list(books = list(list(
title="Book 1",
entry = "entry 1",
publisher = "Books Unlimited",
authors = list(
list(name="...
2
I need to write a dplyr function that creates a customised area plot. So here's my attempt.
area_plot <- function(data, what, by){
by <- ensym(by)
what <- ensym(what)
data %>%
f...
Surreptitious asked 16/10, 2018 at 12:34
3
Solved
I have a tibble like:
tibble(a = c('first', 'second'),
b = list(c('colA' = 1, 'colC' = 2), c('colA'= 3, 'colB'=2)))
# A tibble: 2 x 2
a b
<chr> <list>
1 first <dbl [2]>
2...
4
Solved
I'm trying to do something that seems very simple, but I cannot figure it out. I have a tibble like so:
> df <- tibble::tribble(
~col_a, ~col_b,
1, "A",
2, "B",
3, &...
6
Seems like a basic question and perhaps I'm just missing something obvious ... but is there any way to pluck a sublist (with purrr)?
More specifically, here's an initial list:
l <- list(a = "fo...
4
Solved
Consider the following example data frame
df=data.frame(x=c(0,3,5,0,7,6,0),y=c(0,0,3,0,0,4,0),z=c(8,7,6,8,9,4,3))
I want to remove the first and last rows, where y=0, that is row 1,2 and 7 ...
3
Using the example data below, my goal is to create a table (publication-ready would be great, but fine if not) where I calculate what percent of each group within each column (city, race, and gende...
Despoliation asked 6/3 at 21:0
4
Solved
The table has units in column. How can I separate the units in column name into another column?
Example:
SUBJID
Dose (mg)
Tmax (h)
2001
200
5
2002
200
5
This is what i want.
SUBJI...
2
Solved
I have this dataframe (df):
df <- structure(list(id = c("A", "B", "C", "D", "E", "F", "G", "H",
"I", &q...
6
Solved
I have the following dataset:
I want to calculate impute the NA in the n_j column in the second row with the formula
n_j - (d_j+c_j).
To create the data:
df = structure(list(time_intervals = stru...
2
I love the package but I was wondering how I could change one rule from the tidyverse style: I'd like to keep "=" instead of "<-" for assignment.
I've read that note: http://styler.r-lib.org/ar...
Stockholm asked 2/6, 2018 at 19:26
1
Solved
I've been trying to resolve an issue in VS Code, where the R Language Server is unable to load, and produces the following error message:
R Language Server (8931) started
Error: package or namespac...
3
Solved
I have a dummy variable like so:
df <- data.frame(year = seq(1990, 1997, 1),
x = c(1, 0, 0, 0, 1, 1, 0, 0))
year x
1990 1
1991 0
1992 0
1993 0
1994 1
1995 1
1996 0
1997 0
I want to create a d...
Prevailing asked 16/12, 2023 at 18:36
3
Solved
I would like to filter a dataframe using filter() and str_detect() matching for multiple patterns without multiple str_detect() function calls. In the example below I would like to filter the dataf...
4
Solved
Apologize if it has been already asked but I'm trying to "change" the order of digits of numbers in a vector.
Let's take as an example this vector:
vector = c("5213456",&q...
1
Solved
In my R script, I would like to print a message in the middle of a long pipe (which takes a long time to run) without breaking the pipe. I need this to track the progress of the running pipeline.
I...
2
Solved
I would like to know for each row how to calculate percentage depends on the column?
Here is dummy datasets:
c <- c(10, 20, 30, 40, 50)
b <- c(40, 2, 40, 10, 50)
a <- c(100, 50, 70, 60, 10...
3
Solved
I have a function from a source that uses a couple of inputs, including country name, and return a graph for that country. The first line of the function defines a Country_name object as something ...
1
Solved
Magrittr has those different pipes:
%>% Pipe
%<>% Assignment pipe
%$% Exposition pipe
%!>% Eager pipe
%T>% Tee pipe
What are their differences and use cases?
2
I have a main function which performs a handful of variously complicated (and long-running) computations on some data, it performs these steps using the pipe from tidyverse / magrittr. I would like...
Megaton asked 4/5, 2023 at 14:32
7
Solved
I have data that looks like this:
library(tidyverse)
df <- tibble(
x = c(0, 179, 342, 467, 705, 878, 1080, 1209, 1458, 1639, 1805, 2000, 2121, 2339, 2462, 2676,
2857, 3049, 3227, 3403, 3583,...
1
Solved
For some reason I wanted to run 1:nrow(.), where . refers to the dataframe defined before. It is something like this:
library(tidyverse)
data.frame(1:10) %>%
1:nrow(.)
I get the error Error in...
1 Next >
© 2022 - 2024 — McMap. All rights reserved.