All Questions
73 questions
1
vote
4
answers
133
views
Apply function rowwise() using column names to identify function arguments using mutate()
I've created a tibble where each column is named to correspond to the arguments of a custom function. There are many columns and so I'm trying to avoid having to explicitly call and assign each ...
0
votes
0
answers
76
views
Extracting observations from one dataframe to populate another
I have a very large dataframe with 396212 observations (rows) and 13 variables (columns), including organism name, antibiotic name, gene name and location.
I want to extract the unique observations (i....
0
votes
1
answer
981
views
`tidyr::unnest`: "cant't recycle input" error **ONLY** when using `cols = dplyr::everything()`
Consider the following:
library(magrittr)
sapply(c("dplyr", "tibble", "tidyr"), requireNamespace)
mytbl <- structure(
list(
A = list(c("A.1", "A....
1
vote
1
answer
140
views
Manually parsing geojson into a dataframe
I would like to work step by step to convert a .geojson into a tibble (or dataframe).
Here's a minimalistic geojson example which I stored in a file called test.geojson (note that the geometry field ...
2
votes
1
answer
468
views
Combining column values with column names for some select columns using tidyr unite
Given a dataframe:
df <- data.frame(Col1 = LETTERS[1:4], Col2 = LETTERS[23:26], Col3 = c(1:4), col4 = c(100:103))
I want to combine column with their column names. I know I can use unite from ...
1
vote
1
answer
35
views
How to fill in NA values according to a categorial variable in R
I have some NA values in my data that I would like to fill in according to the filename column. In order words, every observation with the same filename should have the same values in the discipline, ...
0
votes
1
answer
78
views
`tidyr::crossing()` with a list of tibbles unexpectedly reduces rows
Below is a reprex of my confusion. I expect when I cross a 1-row tibble with a 2-row tibble, I get a 2-row tibble. This does work with atomic column types. However, if the 2-row tibble is a list of ...
0
votes
1
answer
268
views
tmerge function in R for time dependent covariates
I have the tibbles df1 and df2 and I want to create df_temp from those using dplyr operations.
The application is for implementing time-varying covariates in a survival model with delayed entry and ...
0
votes
1
answer
49
views
How to split data to make it another column
I am working on a voting data and trying to show most voted two parties. Problem is I want them in columns as, "first_party", "first_votes", "second_party", "...
0
votes
1
answer
27
views
Error in complete() from invalid column/object name
I have a CSV with three columns: a Plot, an integer vector, Species, a character vector, and DBHClass, an integer vector. The CSV looks like this:
##Read in table
library(tidyverse)
PlotData <- ...
1
vote
2
answers
75
views
Transforming a `data.frame` using a character variable containing a string of data
I have a data.frame that contains a character variable, which has a string of additional metadata (sort of a key-value format) that I'd like to have as variables in a data.frame; the metadata variable ...
0
votes
3
answers
135
views
Separate column by string patterns
I have the following example:
structure(list(value = c("./LRoot_1/LClass_copepodo", "./LRoot_1/LClass_shadow",
"./LRoot_2/LClass_bolha", "./LRoot_2/LClass_cladocera&...
1
vote
1
answer
508
views
How to insert new column names to a tibble in r?
I have the following Tibbles.
tmp <- tibble()
tmp2 <- tibble()
tmp <- tmp %>% rbind( colSums( y_matrix) )
tmp2 <- tmp2 %>% rbind( ...
1
vote
1
answer
60
views
R/tidyr- Creating New Data Frame Rows Based On Column Values
Consider the following tibble, which contains meal order data. Variable order_item contains the item ordered. However, sometimes an order contains multiple items, as shown in extra_item1/2.
order_nbr ...
3
votes
2
answers
335
views
Make "tidy" tibble dataset with matrix variable
I have a dataset in a one-row-per-person format, but I want to merge in a dataset as a matrix variable -- basically, if not for the need of the tidy format, I would use a fuzzy join to merge in data ...
1
vote
2
answers
151
views
R tibble with comma separated fields - read/write_csv() incorrectly parses data as double
I hope the title makes sense. I will explain a bit here.
I am working with data that comes from a network performance monitoring tool running synthetic transactions (mimicking user activity by making ...
1
vote
1
answer
91
views
rbind nested tibbles within groups
I have a tibble with a list column of tibbles (with compatible columns). I would like to rbind the tibbles after grouping. Here is a simplified example, where I would like to group on the tpm column:
...
2
votes
2
answers
1k
views
Struggling to unnest tibble (dput, code, and error included) in r
I'm trying to unnest a species count tibble so I can turn it into a dataframe. The last four columns are species counts and are currently in 'list' form (seems nested?). I'd like to have each column ...
13
votes
1
answer
9k
views
Is there way to pivot_longer to multiple values columns in R?
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("...
3
votes
3
answers
814
views
How to collapse a tibble by combining rows into a list?
As part of a dplyr/tidyr wrangling pipe, I arrived at a tibble that looks like that:
trb <-
tibble::tribble(~person, ~data_name, ~data_obj, ~some_string,
"chris&...
1
vote
3
answers
418
views
Replace NULL value in nested tibble / dataframe
I have this tibble of tibbles:
a = tibble(a = c(1:3))
df <- tibble::tibble(a1 = list(a,a), a2 = list(NULL,a))
# A tibble: 2 x 2
a1 a2
<list> <...
2
votes
4
answers
863
views
How to generate a list-column holding named-vectors, when grouping by other data frame variables?
Having a data frame, I want to generate a new list-column containing named vector(s) (one vector per row). Each vector derives its names and values from 2 other data frame columns. But I'm stuck ...
1
vote
3
answers
61
views
add five items on list to each value in column of dataframe
Not really sure how to phrase the title, but what I have a list of names in a dataframe and I would like to add five items from a list to each name such that each name and one item is a row. So,
Name ...
1
vote
1
answer
35
views
Read human-readable concatenated tables to a tibble
I have some human-readable tab-separated data with the following form:
Table_1
10 20 30
30 40 50
10 20 40
Table_2
20 30 40
10 50 60
30 20 10
...
1
vote
3
answers
59
views
Split column of strings into matrix of strings using regex with colnames based on part of match
I'm creating tibble from the gene descriptions in a FASTA file of protein coding sequences. Here's some example data I want to process
seqDescriptions<- c( "lcl|NC_003888.3_cds_NP_624362.1_1 [...
0
votes
1
answer
150
views
pivot_longer on a mix of matrix columns and regular vector columns
I have a tibble where some columns are matrices. Here's a toy example:
library(dplyr)
library(tidyr)
dat <- structure(list(id = 0:5, matrix_column = structure(c(-1.34333431222985,
...
0
votes
1
answer
411
views
How to delete individual column indices of a tibble?
I have a tidyverse::tibble which I produced from prior calculations. Unfortunately, my columns have different indices and given that I want to transform the tibble using tidyr::pivot_longer(), ...
0
votes
2
answers
42
views
efficiently make an all-by-all co-incidence tibble from an incidence tibble
I have a tibble that encodes which people like which foods. There are ~3M rows, ~92k people, and ~2k foods. I have calculated how popular each food (what % of people like it). From that I have ...
-1
votes
2
answers
262
views
How to paste strings between tibble's character column and rows in a nested list-column
I have a tibble with one character column and one list-column that nests dataframes. I want to collapse the dataframes in the list-column (using dplyr::bind_rows()) and append the respective value ...
2
votes
1
answer
34
views
Expand tibble of email dataset in R
I have a massive tibble of my email data which looks like the following:
library(dplyr)
emails <- tibble(
from = c('[email protected]','[email protected]','[email protected]',
'...
0
votes
0
answers
968
views
Why does pivot_longer() only work when I specify the dataframe inside the brackets, not with pipe notation?
I was trying to rearrange a dataframe using dataframe %>% pivot_longer( ) but would keep getting errors however I tried to specify the cols argument.
For instance, trying cols = (!colname) I'd get:
...
4
votes
2
answers
841
views
Using tidyverse to "unnest" a data.frame column inside a tibble
I'm working with some data which is returned from a www call which jsonlite and as_tibble somehow convert into a data.frame column.
This result data has an Id integer column and an ActionCode data....
1
vote
1
answer
131
views
Nesting and combining data columns while changing type of nested objects
I'm given a "reference" data frame that summarizes which variables in my main data (not shown here) should be filtered and by what values. Two such variables, for example, are age and color:
...
9
votes
3
answers
533
views
Pivoting wide to long format and then nesting columns
I'm given data that comes in a wide format. Each row pertains to a variable external to the current table, and possible values relevant for that variable. I'm trying to: (1) pivot to long format, and (...
1
vote
2
answers
101
views
How to Split an R List Containing Character Vectors of Varying Lengths Into Specific Columns?
I have some data in JSON format, that using jsonlite I was able to read into a data frame in R. The data I'm working with is in lists, where each list contains character vectors of different lengths. ...
1
vote
2
answers
51
views
How to pivot a single cell dataframe
I have encountered such a simple challenge, and yet don't know how to do this properly.
library(tibble)
library(dplyr)
# I have this single-cell dataframe
tibble::tribble(~red,
"...
2
votes
3
answers
355
views
Convert nested list to dataframe: extract only specific elements of interest
I've seen many similar questions, but couldn't adapt to my situation. I have data that comes as a nested list, and want to convert it to a data frame in a certain way.
my_data_object <-
list(...
2
votes
3
answers
355
views
How to identify columns by pattern and convert it to datetime using R?
I have a data frame called data like as shown below
structure(list(NRIC_ID = c(1234L, 4567L, 1234L, 3578L, 2468L),
ADMIT_DATE = structure(c(2L, 3L, 4L, 5L, 1L), .Label = c("11/11/2011",...
0
votes
2
answers
263
views
Selecting some columns and assigning properties to columns in a data frame
In my mind, when I deal with a data frame, I like to consider that I may have subgroups of rows and subgroups of columns that I may want to distinguish or to refer to later in my analysis —for ...
1
vote
2
answers
69
views
R How to vectorize a filter table lookup
I am looking to find a way to vectorize a table lookup. Here is an example of my expected input/output without using a loop.
library(dplyr)
library(tidyr)
input <- tibble(
value = c(2, 1.5, 3),
...
3
votes
1
answer
127
views
Is there more efficient or concise way to use tidyr::gather to make my data look 'tidy'?
I am new to using tidyverse. I want to see if I am being as efficient/concise as possible using the functions in this package. I suspect I am not.
My original data has the key sym as part of each ...
3
votes
2
answers
1k
views
Use of dplyr::sym() within "mutation" while creating a list tibble column results in an error is_symbol(x): object '.x' not found
In the following code I try to create a list tibble column at the right end of mtcars, in which: each member of the list is a tibble with rows of mtcars tibble where vs >= 1 and !is.na(gear).
In ...
0
votes
2
answers
528
views
Adding a newcolumn using tidyverse in R?
I have two datasets data1 and data2 which is given in the form below
> data1
x y z
apple 3 3
banana 4 3
mango 1 1
pear 2 1
lemon 3 ...
0
votes
1
answer
261
views
Purrr safely creating lists of lists
I've used safely to catch an error which occurs in my code when I'm purring. However, the result from safely is much more complex than I anticipated.
First we create the necessary functions and ...
1
vote
1
answer
908
views
Error in `pivot_longer()` argument when updating `tibble` versions
Context
We would like to manage data from dat_1, in wide format, to dat_2, in long format. In order to perform it, we thought to use tidyr::pivot_longer() with argument names_pattern = '(.+)_(.+)'. ...
1
vote
1
answer
381
views
Unpacking a list-column of multi-row tibbles while preserving the number of rows
I have a tibble in which one column is a list of tibbles. Some tibbles in
this list have more than one row. Here is a minimal example:
library(tibble)
tmp <- tribble(
~x, ~y,
1, tibble(a=1, ...
1
vote
1
answer
67
views
Split list column into multiple integer columns on R dataframe
I have an R dataframe with 2 columns: ID of the transaction, and a list of products associated
I need a dataset that have the same number of rows (a row per transaction), a number of columns equal to ...
1
vote
0
answers
152
views
subsetting a tibble using logical matrix?
I have a logical matrix. How can I use this to subset a tibble and replace the values?
For example:
if we have a dataframe:
dat <- head(iris)[1:3]
dat[dat>3.5] <- 0
dat
What if I have a ...
0
votes
3
answers
46
views
Create Dataframe w/All Combinations of 2 Categorical Columns then Sum 3rd Column by Each Combination
I have an large messy dataset but want to accomplish a straightforward thing. Essentially I want to fill a tibble based on every combination of two columns and sum a third column.
As a hypothetical ...
1
vote
2
answers
89
views
Apply operation on all pairs of rows
I have a tibble in this format:
position condition replicate value
<dbl> <chr> <chr> <dbl>
1 10 1 a 0.16
2 10 1 b ...