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.
1,323
questions
0
votes
0
answers
41
views
How would one go about converting a list with differing numbers of rows to a dataframe?
I'm trying to convert a list of data from a series of files into a dataframe. I'm using the tibble package to do so.
mydata <- as_tibble(mylist, .name_repair = "universal")
This method ...
3
votes
2
answers
82
views
How to get an object's name after it's sent to a function, within a tibble?
I want to get an object after it's sent to a function. This question has been solved many times before on this site with a deparse(substitute(x)) trick. I am getting unexpected behavior when I use ...
0
votes
1
answer
55
views
Factor levels out of order in tibble
First time asking a question here and very new to R, so please bear with me if I format/phrase something incorrectly. Thanks in advance for your help!
I have multiple columns stored as factors in my ...
0
votes
2
answers
65
views
Create a new column with the sum of the values from some columns in a tibble on R
I have a tibble like Table1, and I want to group some columns by the sum of their values for every row, creating a new column with the results and replacing the summed columns, like Table2.
Table1
| ...
1
vote
3
answers
48
views
Add rows to complete melted tibble
Consider this "melted" tibble:
structure(list(country = c("Canada", "US", "Canada"), gender = c("male", "male", "female"), count =...
1
vote
1
answer
43
views
Mutate is adding $ dollar sign to column name
I have the data below that I'm using to calculate another column using the function below. Using pick with starts_with and ends_with ends with the result having a $ in the column name with the input ...
4
votes
4
answers
88
views
Mutate new column in tibble with values of other columns by matched pattern
My tibble:
df <- tibble(a = c(1,2,3,4,5,6,7,8,9,10),
b = c("", "", "1", "", "1", "3", "2", "", "...
2
votes
1
answer
42
views
A tibble with a list as a column into long format in R?
Let's assume we have a following tibble:
set.seed(123)
mightyTibble <- tibble(
year = 1:10,
revenue = 1000*rgamma(10,2000,3000),
cost = 100*rgamma(10,2000,3000),
items = lapply(1:10, \(...
1
vote
4
answers
57
views
How can I combine to columns that consist of lists?
I want to combine the two columns position and . They look like this:
position = c("123, 45", "67, 891, 23") and substitution = c("A/B, C/D", "E/F, G/H, J/K") ...
0
votes
1
answer
45
views
A way to mutate a new column in every dataframe in a list of dataframes?
I have a list of files that I want to import as tibbles, then mutate a new column onto each tibble based on an ifelse statement for a threshold. I didn't want to use a loop, so I have been trying to ...
0
votes
0
answers
43
views
A way to sort files into tibbles based on filename in R?
I have a large list of files and want to sort columns from certain files in the list into two tibbles. The file names contain the phrases I need to identify which files go where, but I can't figure ...
0
votes
1
answer
13
views
Create series of tibbles running through title by item in list of strings
I have a list of strings:
lst = c('item1', 'item2', 'item3', ..., 'itemN')
and I have a dataframe df with column df$item equal to one of item in lst above. Using a for loop, I would like to create a ...
0
votes
0
answers
43
views
error with rstatix::tukey_hsd loop: no applicable method for 'tbl_vars' applied to an object of class "NULL"
given the dataset df
df<-structure(list(stream = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, ...
1
vote
2
answers
40
views
R: Save Each For-Loop Iteration As New Named List inside List
I have a for-loop that extracts equal-length numerical ranges and appends each range as a new list within a list. After the for-loop completes I want to turn the list of lists into a data frame and ...
1
vote
3
answers
50
views
tibbles and lists - r wrangling dplyr
I am trying to convert a bunch of points to polygons.
I found a nice example of what I'm trying to accomplish here: Convert data frame containing coordinates of polygons to sf
I'd like to try their ...
0
votes
0
answers
27
views
Wrong tibble printout in R VSCode
I have recently had to reset my PC. After reinstalling VSCode, packages and dependencies, I have started to run R code as usual. However, the printout that I get from tibbles in the R console seems ...
0
votes
1
answer
45
views
How can I sum up columns in a Matrix or Dataframe?
I want to to sum up columns 3-7 of my Matrix(1-7). But in column 1 are words (so "character").
So if I use the rowSums function I get an Error "x must be numeric" (also when I ...
1
vote
1
answer
45
views
replacing reshape2::decast() with tidyverse or R base
I was wondering if there is an equivalent for reshape2::dcast from tidyverse or even Base R in my code below to produce the same output below?
library(reshape2)
dat=structure(list(row = c("L2DA&...
0
votes
0
answers
10
views
How to I make a list of tibbles? [duplicate]
I have a function that returns a tibble/dataframe. I need to run it several times and put the results into one large tibble. But everything I've tried throws an error or breaks the tibble down into a ...
1
vote
4
answers
46
views
R Duplicating tibble rows while incrementing one column?
I'm working with tibbles and fun again, and have run into a problem while attempting to increase the number of days of my data set.
Consider the following tibble:
tibble(food = c(rep("sunflower&...
0
votes
1
answer
130
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....
0
votes
1
answer
29
views
Vectorialised sums, with weights pulled from another tibble
I have two tibbles, for example
library(tidyverse)
A <- tibble(
G = c("A","A","B"),
a = c("a", "b","c"),
e = c(1, 2, 3))
Z <- ...
1
vote
1
answer
43
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
4
answers
109
views
Creating multiple NEW columns using across() in R [duplicate]
The difference between my question and existing questions is that I want to create new columns with mutate that do not depend on existing columns.
Some dummy data:
library(dplyr)
dat <- tibble(
...
1
vote
2
answers
66
views
Why does kable in R undo an summarytools frequency option to not display cumulative percentage?
I found an odd quirk or maybe an intentional feature and trying to find a more elegant solution. Any ideas are appreciated. Reproducible code example below, but I wasn't able to recreate the tables ...
1
vote
1
answer
39
views
Exporting several tibbles to separate sheets in excel
I'm looking for a way to automate some data clean-up. So far, I've figured out how to import several excel workbooks and all their sheets into R using the following:
my_data = expand_grid(
file = ...
1
vote
2
answers
51
views
Summarizing rows of a data frame in R
I tried the following to convert my Data into my Desired_output without success.
I wonder what I'm missing?
library(tidyverse)
group_by(Data, ID) %>%
summarise(Den=Den,
Num=Num,
...
0
votes
1
answer
34
views
R [Dplyr]: Adding column after applying Summary function
I hope you are able to advise in how effectively use the dplyr package.
I have a data.frame with three columns, country, company name and satisfaction score.
Ultimately, I would like to find the nth ...
1
vote
2
answers
62
views
Combine sets of 2 rows based on different values of variables
I have the following table (a tibble)
Year
Name
n
1969
Alice
24
1969
Bob
25
1969
Charlie
33
1970
Alice
13
1970
Bob
20
1970
Charlie
10
1971
Alice
23
1971
Bob
10
1971
Charlie
16
etc.
I want ...
0
votes
0
answers
51
views
Understanding curly-curly operator
How does that code works? The main goal was to asign a string to a variable and then make a dataframe which the first column is the string.
So in this case you could do that:
# column1 <- "...
0
votes
1
answer
33
views
How to save the output results of Sen's Slope
I am using this code to calculate Sen's Slope
x1<-data$Prec_45_BC
Prec45<- sens.slope(x1)
Its output results are as below. How can I save them in the table form and further export them to CSV.
...
-1
votes
1
answer
46
views
universal transpose tibble function
After much frustration, I have written my own function to transpose Tibbles I've attempted to make it universal so I don't have to rewrite it in the future
Its purpose is a simple transpose like is ...
0
votes
1
answer
47
views
Preserving decimal data format when writing r tibble data to .txt file
I am trying to write a tidyverse tibble to a text file while maintaining decimal format in the out put file, but all write functions seem to convert decimal data with quite a few significant digits. ...
0
votes
0
answers
75
views
R-Shiny: Editable DT Table Issue
I am fairly new to R shiny. I am trying to create a dynamic table where user enters the column name and values. Then display this as a tibble which can be edited.
But however, even though I am able to ...
1
vote
1
answer
39
views
How to convert first column in df as a header and keep original header as sub-header
I do have this type of data:
id <- c('id_1', 'id_1', 'id_1', 'id_1', 'id_2', 'id_2', 'id_2', 'id_2')
var1 <- round(runif(n = 8, min = 0, max = 10), 4)
var2 <- round(runif(n = 8, min = 0, max ...
2
votes
1
answer
82
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 ...
-2
votes
1
answer
107
views
Conflicts or errors in the tune and tidymodels packages using information gain from the colino package or recipeselectors
This code was working until yesterday, when I uninstalled the recipeselectors and colino packages. I've looked everywhere and no one has reported a similar error.
Link to download the database used:
...
0
votes
0
answers
12
views
A problem occurred when trying to limit the data set
I want to limit the MARPOR data set to these three specific variables. However, when I run the code, I keep getting the results only for two or sometimes three candidates, namely "Anthony ...
0
votes
0
answers
51
views
The which() function in R is not working when comparing two numerical tibbles
I am trying to compare columns from two different tibbles to find the corresponding row in dat2 to fill. However, I keep getting a integer(0) result for the second part of the which function. The two ...
0
votes
1
answer
98
views
Finding quartiles from a cumulative distribution table
I am have a grouped tibble (tbl_df) containing cumulative frequency distribution from a combined dataset, where the column "size" contains the object size ranging from 30 to 800, the column &...
0
votes
0
answers
23
views
How do I merge data from 2 columns together, into 1, in R? [duplicate]
I'm using dplyr (actually dbplyr) and I have 2 tables.
I've tried to reproduce samples below:
df1 <- tibble('y' = c(2001,2001,2001,2001,2002,2002,2002,2002), 'id' = c(7,8,7,8,7,8,7,8), 'c' = c(0,0,...
1
vote
1
answer
52
views
Tables stacked below each other in csv - How do I import them in R?
I have a csv file that looks like this
Header, Car, LapTime
1, Spa, 0
0, Ferrari, 2.1
0, Aston Martin, 2.3
1, Monza, 0
0, Ferrari, 2.5
0, Ford, 2.6
0, Aston Martin, 2.4
That is, the csv contains ...
0
votes
3
answers
54
views
extracting selected estimate and CI from a linear mixed model
I need help in extracting estimate and CIs only for yr_qun variable from my linear mixed model. when I run the following code I get
Error:
! Tibble columns must have compatible sizes.
• Size 30: ...
0
votes
1
answer
34
views
How to use mutate() and ifelse() to create a column based on a match or multiple matches in different data frame
I want to join one data frame (df) with multiple rows on the condition that there is a match for datatossedtest$StationID in datasummary$StationID (see below). I then need certain columns from the ...
0
votes
2
answers
632
views
The `.data` argument of `add_column()` must have unique names
I want to relegate the rownames to a column labeled Sample. All the rownames are unique.
df <- tibble::rownames_to_column(df, "Sample")
Traceback:
Error:
! The `.data` argument of `...
0
votes
2
answers
42
views
Apply a mathematical operation to all columns of dataframe by group [R]
I have the given dataframe :
df <- structure(list(id = c("2023-02-15_10-30-49", "2023-02-15_10-30-49",
"2023-02-15_10-30-49", "2023-02-15_10-30-49", "...
0
votes
0
answers
12
views
Managing a table with multiple sublists
I am doing some data exploration and iterated an ANOVA through a large number of variables (~ 300) and then did a pairwise comparison on the significant findings. I know from a statistical point of ...
0
votes
1
answer
50
views
Making tibble construction (of columns, rows and data) in R more efficient
I wanted to create a mini project in R, namely the construction of a 7x7 tibble with random data inside.
The goal was to perform data analysis on the data inside the tibble. The outcome was successful,...
4
votes
4
answers
108
views
Range calculation by row in R
I have a 4x4 tibble, and I'm practicing various dplyr functions on it.
I would like to calculate the range of each row, and display the range of that row as a single number in a new column.
Here is my ...
1
vote
3
answers
64
views
Can I get Tibbles to Display like Data Tables
One of the things I love about data tables is that when you show them from the command line they give you the head and tail of them....
I am now being made to work in dplyr a lot and find it very ...