Questions tagged [tibble]

tibble could refer to an R class (tbl_df class), which is an improved data frame with stricter checking and better formatting. tibble could also refer to an R package providing functions to create and manipulate a tibble.

1309 questions
4
votes
2 answers

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.frame column with two internal columns. these show…
Stuart
  • 66,722
  • 7
  • 114
  • 165
4
votes
3 answers

How to add rows to a tibble at a specific place (index) without specifying column names? (R)

I have a tibble with very many columns. I need to add a row to it at a specific location (e.g. before row 2). How can I do this without typing column names before the values? E.g. this is what I must do (imagine more columns, V1, V2, V3,…
PaulG
  • 276
  • 2
  • 11
4
votes
2 answers

How to print tibble without row.names / row numbers

Tibbles print with row numbers as row names. See 1, 2 in the left margin below: tibble::as_tibble(mtcars) # A tibble: 32 x 11 mpg cyl disp hp drat wt qsec vs am gear carb
Sam Firke
  • 21,571
  • 9
  • 87
  • 105
4
votes
2 answers

Create a tibble with tribble using defaults that don't cause an error, e.g. like tibble

A recent update of packages means that this code for neatly making a tibble with tribble() (then used to make a table) no longer works. library(dplyr) table_data_1 <- tribble(~"Header1_A", ~"Header2_A", 0.19, 0.20, …
Mark Neal
  • 996
  • 16
  • 52
4
votes
1 answer

How to create a new type which plays well inside data.frame?

I guess there are several ways to do this. Hence, the answers to this question could be subjective, if not opiniated. So I will try to narrow the problem, and give you the details of what I have already done. Context I am working with the R6 package…
pietrodito
  • 1,783
  • 15
  • 24
4
votes
2 answers

How to mutate NA on multiple rows (rowwise) in tibble

I spend sometime try to figure out how to mutate NA values on multiple rows on row perspective in tibble, the tibble has 3 observations and 6 variables, generate below: df <- data.frame(ID = c(1, 2, 3), Score1 = c(90, 80, 70), …
Lampard
  • 394
  • 7
  • 23
4
votes
2 answers

dplyr - mutate with variable column names

I have a tibble containing time series of various blood parameters like CRP over the course of several days. The tibble is tidy, with each time series in one column, as well as a column for the day of measurement. The tibble contains another column…
user11130854
  • 333
  • 2
  • 9
4
votes
3 answers

Using group_map to apply function to each group in grouped tibbles

How do I use group_map to apply a custom function to each group in a grouped tibble. I want to find the mean weight of each group in kg, and create a new column for each case. So every case in each group should have the same mean weight. # custom…
TYL
  • 1,577
  • 20
  • 33
4
votes
1 answer

Is there a tidy way to mutate individual cells in a tibble?

How do I change individual cells, preferably using the %>%? For example: library(dplyr) df <- iris %>% slice(1:5) Produces this: Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 …
william3031
  • 1,653
  • 1
  • 18
  • 39
4
votes
1 answer

use a personnal print method inside print.tbl

I have created a class called time. This is a dummy example which return seconds as minute. This works well, But the print.time function is not used inside a tbl. Any ide how I can adapt the display inside a tbl ? Regards see reprex…
Vincent Guyader
  • 2,927
  • 1
  • 26
  • 43
4
votes
0 answers

How to extract forecasting errors from all training sets into a single data frame in R?

By forecasting errors, I mean the differences between predicted and actual values. I am doing a time series analysis using a deep learning model called the long-short term memory (LSTM) based on this great article. The author distributed the data…
T-T
  • 693
  • 1
  • 10
  • 24
4
votes
2 answers

Select variables from list of tibbles using names in each tibble

I have a list of tibbles or data frames (each one with a name in the list) and I want to: (1) create new columns with the same name long.col in each tibble from variables with different names; (2) do this by matching from another tibble with the key…
Crimc
  • 195
  • 17
4
votes
1 answer

Why is R not angry with my tibble: the tale of the dangling comma that could

R wants things to be just so. Commands must be exactly correct, and quite rightly so. Thus, dangling commas are bad. For example, on a vector: > c(1,) Error in c(1, ) : argument 2 is empty Or a data frame: > data.frame(a = 1,) Error in…
Scransom
  • 3,175
  • 3
  • 31
  • 51
4
votes
5 answers

bind_rows to each group of tibble

Consider the following two tibbles: library(tidyverse) a <- tibble(time = c(-1, 0), value = c(100, 200)) b <- tibble(id = rep(letters[1:2], each = 3), time = rep(1:3, 2), value = 1:6) So a and b have the same columns and b has an additional column…
Cettt
  • 11,460
  • 7
  • 35
  • 58
4
votes
3 answers

Calculating convex hull for each group in R

I have a following data set: structure(list(time = c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L), x = c(40.8914337158203, 20.0796813964844, 13.9093618392944, 17.1513957977295,…
Kuba_
  • 886
  • 6
  • 22