tidyr Questions
5
Solved
Using the tidyverse a lot i often face the challenge of turning named vectors into a data.frame/tibble with the columns being the names of the vector.
What is the prefered/tidyversey way of doing t...
2
Solved
I have the following tibble, which has two nested columns:
library(tidyverse)
df <- structure(list(a = list(c("a", "b"), "c"), b = list(c("1", "2",
"3"), "3"), c = c(11, 22)), class = c("tbl_d...
2
Solved
I am using R 3.5.3. When I run
library(tidyr)
library(dplyr)
df <- data.frame(x = c(NA, "a.b", "a.d", "b.c"))
df %>%
separate(df[1], c("A", "B"))
I got
Error in separate(., df[1], c...
2
Solved
I have some random effect coefficients extracted from a R model object. For a random intercept, they look like this:
xx <- data.frame(
`Estimate.Intercept` = c(-0.1, -0.2),
`Est.Error.Interce...
3
Solved
I have a data.frame where some cells contain strings of comma separate values:
d <- data.frame(a=c(1:3),
b=c("name1, name2, name3", "name4", "name5, name6"),
c=c("name7","name8, name9", "na...
3
Solved
To unnest a data frame I can use:
df <- data_frame(
x = 1,
y = list(a = 1, b = 2)
)
tidyr::unnest(df)
But how can I unnest a list inside of a list inside of a data frame column?
df <- ...
1
Solved
I'm trying to use pivot_longer to enlongate my dataframe, but I don't need it to be fully long, and would like to output multiple "values" columns.
Example:
df <- tibble(
ids = c(&quo...
6
Solved
I have a data frame which I need to transform. I need to change the unique rows into single columns based on the value of a column.
My data below:
df1 <- data.frame(V1 = c("a", "a...
Bacolod asked 17/3, 2022 at 18:40
1
I have a data.frame of hospital data with 11 million rows.
Columns: ID (chr), outcome (1|0), 20x ICD-10 codes (chr).
Rows: 10.6 million
I wish to make the data tidy to allow modelling of diagnosti...
Samphire asked 15/3, 2022 at 11:52
4
Solved
3
Solved
I am trying to figure out how to use pivot_longer from tidyr in the following example. This is how the original table called dat_plot is structured like:
year organizational_based action_based ide...
Jorum asked 13/1, 2022 at 17:26
2
Solved
Using basic R, I can transpose a dataframe, say mtcars, which has all columns of the same class:
as.data.frame(t(mtcars))
Or with pipes:
library(magrittr)
mtcars %>% t %>% as.data.frame
...
8
Solved
I have a dataframe in a wide format, with repeated measurements taken within different date ranges. In my example there are three different periods, all with their corresponding values. E.g. the fi...
4
Solved
If you want to try these new functions (pivot_wide and pivot long), you need to install the development version of tidyr:
devtools::install_github("tidyverse/tidyr").
But I have not manag...
6
Solved
I am trying to pivot a table that has headings and sub-headings, so that the headings go into a column "date", and the subheadings are two columns instead of repeating.
Here is an example...
Unwilled asked 5/1, 2022 at 20:25
5
Solved
This is my dataframe:
df <- tibble(col1 = c("1. word","2. word","3. word","4. word","5. N. word","6. word","7. word","8...
4
Solved
I have data that looks something like this
df = data.frame(name=c("A","A","B","B"),
group=c("g1","g2","g1","g2"),
V1=c(10,40,20,30),
V2=c(6,3,1,7))
I want to reshape it to look like this:
df...
3
Solved
I love the reshape2 package because it made life so doggone easy. Typically Hadley has made improvements in his previous packages that enable streamlined, faster running code. I figured I'd give ti...
1
Solved
Suppose I have a data frame with a bunch of columns where I want to do the same NA replacement:
dd <- data.frame(x = c(NA, LETTERS[1:4]), a = rep(NA_real_, 5), b = c(1:4, NA))
For example, in t...
Kempis asked 13/12, 2021 at 21:1
4
Solved
I would like to standardize variables in R. I know about multiple approahces how this can be done.
However, I realy like using this approach bellow:
library(tidyverse)
df <- mtcars
df %>%
...
3
Solved
I have the following data frame:
library(tidyverse)
dat <- tribble(
~Scenario, ~V1, ~V2, ~V3, ~V4,
1, 0.97, 0.46, 0.79, 0.25,
1, 0.21, 0.45, 0.23, 0.63,
1, 0.95, 0.97, 0.07, 0.61,
1, 0.93,...
5
Solved
I have a dataframe where I want to separate a column that contains month and year:
library(tidyverse)
df <- data.frame(
month_year = c("Januar / Janvier 1990", "Februar / Février...
2
Solved
So I have this dataset
# A tibble: 268 x 1
`Which of these social media platforms do you have an account in right now?`
<chr>
1 Facebook, Instagram, Twitter, Snapchat, Reddit, Signal
2 ...
2
Solved
I converted a JSON file into a data.frame with a a nested list structure, which I would like to unnest and flatten. Some of the values in the list are NULL, which unnest does not accept. If I repla...
4
Solved
Problem:
Is there a simple way to get all combinations of two (or more) identical vectors. But only show unique combinations.
Reproducible example:
library(tidyr)
x = 1:3
expand_grid(a = x,
b =...
© 2022 - 2025 — McMap. All rights reserved.