Most voted "tidyverse" questions
`tidyverse` is an R package that installs other packages for data processing and visualization, such as `dplyr`, `purrr` and `ggplot2`. Ideally, questions should not be asked with the `tidyverse`tag, but rather with the `r`tags and the environment package that is generating the doubt.
Learn more…45 questions
Sort by count of
-
7
votes1
answer377
viewsSize of panels with facet_wrap
I’m making some panel charts on ggplot2. See the example below: library(ggplot2) ggplot(mpg, aes(x=displ, y=hwy)) + geom_point() + geom_smooth(method="lm", se=FALSE, colour="black") + facet_wrap(~…
-
7
votes2
answers292
viewsCumulative count of group occurrences on dates
I have a data set similar to the one below. It has a column with dates and another with occurrences of groups on these dates. data grupo 1 2019-01-01 a 2 2019-01-01 a 3 2019-01-01 a 4 2019-01-01 a 5…
-
6
votes1
answer360
viewsWhat is the use of the functions with underline (_) at the end?
Consider the functions of the following Packages: dplyr library(dplyr) gorup_by_ summarise_ mutate_ transmute_ tidyr library(tidyr) gather_ spread_ separate_ unite_ What is the usefulness of these…
-
5
votes1
answer85
viewsWhat are columns-lists of a data.frame?
The tidyverse stimulates the use of columns-list in data frames.. But, after all, what are columns-list? on what occasions they are commonly used? they can be created with the r-base or just as…
-
4
votes1
answer95
viewsHow to use dplyr within a function?
Let’s say I wanted to create a function that internally uses some functions of dplyr or any package from tidyverse using this kind of syntax. For illustration purposes: exemplo <- function(df,…
-
4
votes1
answer104
viewsManipulation of columns-list
I have a tibble so-called my, which contains the column-list data library(tidyverse) dataset<-data.frame(matrix(rnorm(6*30,1000,100),ncol=6)) cluster<-kmeans(dataset,centers=3)…
-
4
votes1
answer123
views'dot Plot' relative to mean with standard deviation
Good morning In the attached graph, the points refer to the value of the average selectivity of each species. On this chart, I’d like to: 1) have larger font sizes of smaller body mass <9kg…
-
4
votes1
answer90
viewsMerge into two worksheets format . csv in R
I’m doing a job using the transparency portal, I need to join two databases prof1.csv and prof2.csv. The final result of merge, that I named prof.csv, is doubling rows due to columns 18 of gross…
-
4
votes1
answer72
viewsHow to transpose from "wide" to "long" (wide to long) with several variables?
I have a dataframe with multiple variables, as in the example below: df <- read.table(header=TRUE, text=" ID COR TIPO SITUACAO_2016 SITUACAO_2017 SITUACAO_2018 SITUACAO_2019 SITUACAO_2020…
-
3
votes1
answer83
viewsDownlad books in Portuguese gutenbergr
I am trying to download books from the Gutemberg project using the "gutenbergr" package. I use the following command: teste <- gutenberg_download(c(40409, 31971, 17515, 42942), meta_fields =…
-
3
votes4
answers101
viewsDealing with dates of heterogeneous formats in R
I have 236 files in . csv that have all the same columns. My goal is to join them all into one data frame only. However, each of them has 4 columns with date and time values. The problem is in the…
-
3
votes1
answer438
viewsHow to increase Y-axis scale marks in graphics in ggplot2?
I have a chart with very long scale marks between you, I’d like to increase the amount, but I don’t know how it’s possible. I would like to increase the number of values in the Y axis, for example,…
-
3
votes1
answer50
viewsWhat does the "~" operator mean in tidyverse context?
Suppose the data set below: df_1 <- structure(list(var_1 = c(42.0324095338583, 86.828490421176, 42.4499513395131, 87.8373390808702, 69.4962524808943), var_2 = c(52.6775231584907,…
-
3
votes1
answer78
viewsHow do I distribute the content of a column to other columns in R?
I’m trying to distribute the contents of one column in another 3 columns. I have the following Data Frame: library(tidyr) df<-data.frame(Coluna= c('2237-5953', '(RE) PENSANDO DIREITO', 'B4',…
-
2
votes1
answer77
viewsHow does it work and how to use the Reprex function of R?
In researches right here in Sopt I saw suggestions of reproducible examples. One of them was the function reprex(), I researched about and saw that its use is specific for HTML, Github and here in…
-
2
votes1
answer49
viewsCreate column with another column value if conditon is TRUE
I am trying to create a column x, with the value of column A, if the value of column B == X, if not = 0 Example: sales<-c(100,140,200,300,20,1000,200,3000)…
-
2
votes1
answer1724
viewsHow to change the color scale on a chart in R
I have a bar chart of Brazilian states. The color of the state bar is according to the region that it belongs to. The color scale was automatically set by ggplot2, I would like to exchange these…
-
2
votes1
answer44
viewsHow to use which.max in a long-format dataframe?
I have a DF in long format and tested the following code: library(tidycovid19) # Pacote do GitHub - https://github.com/joachim-gassen/tidycovid19 library(tidyverse) updates <-…
-
2
votes1
answer113
viewsHow to specify facet_grid columns in ggplot2?
I’m using Google’s mobility data to compile some charts, I needed to make a 5x5 chart, where in the rows would be the states and in the columns, the locations. I tried to use the facet_grid, but it…
-
2
votes1
answer58
viewsProblems with sum() function inside summarise using plyr and tidyverse!
Hello, good afternoon! I’m finding it difficult to use tidyverse, to perform a stacking function + summarise(soma=sum(value)) + pop =…
-
2
votes1
answer79
viewsCalculate percentage with dplyr::add_count
how it would be possible to calculate percentages with the dplyr::add_count()? To calculate with the dplyr::count() is very simple, as follows: library(tidyverse) dt <- Titanic dt %>%…
-
2
votes1
answer245
viewsRelative Frequency Table - R / R Studio (% Daily Sales Determined Date/Product)
I have tried in every way to write a code that creates a relative frequency table, but I could not. I have a dataframe with the following variables: RANGE_DIAS: Interval of days between order date…
-
2
votes1
answer26
viewsHow to make a filter based on a condition?
I have a date.frame with two columns (CLASSWK and IND) and I’d like to apply a filter based on one condition, but I’m unable to do that. I have a column CLASSWK, that I only want to keep values that…
-
1
votes1
answer117
viewsOrdering Feeling Table(Tidytext)
I am trying to create a table based on the Chapter-Book-Feeling-n leaving the Chapter always in original order:"The Boy Who Lived", "The Vanishing Glass," "The Letters from No One", "The Keeper of…
-
1
votes0
answers316
viewstidyverse_conflicts()
Loading the tidyverse package shows that there are some conflicts. -- Attaching packages --------------------------------------- tidyverse 1.2.1 -- v ggplot2 3.0.0 v purrr 0.2.5 v tibble 1.4.2 v…
-
1
votes1
answer18
viewsCompile information on the same line
I need help to compile information on a single line. Here’s an example of df: library(tidyverse) df <- tibble( Name = c("A", "A", "B", "B"), Week = c(100, NA, 200, NA), Weekend = c(NA, 2000, NA,…
-
1
votes1
answer63
viewsTidyr spread does not return to original data
Consider the data.frame: df_1 <- data.frame( a = replicate(6, runif(30, 20, 100)), b = rep(c(LETTERS[1:5]), times = 1, each = 6) ) Use of gather: library(tidyverse) library(magrittr) df_1…
-
1
votes0
answers32
viewsIs there any functional difference between bind_rows (dplyr) and rbind.Fill (plyr) in R?
I would like to know if using one function instead of another there would be some differential in relation to the final dataframe to be produced. There were situations I tried to accomplish…
-
1
votes1
answer44
viewsIf_else and Filter
I’m trying to give a filter: library(tidyverse) library(lubridate) filter(indicesBrutos, if_else(day(NomDataIn) != 1, filter(Mes >= NomDataIn-30, Mes <= CMData)), filter(Mes >= NomDataIn,…
-
1
votes1
answer265
viewsRemove "Nan" from a data.frame in R
I have a data.frame with two columns that have some NaN and Inf and I’d like to replace them with NA. I was using this code, but it didn’t work: library(tidyverse) dados <-…
-
1
votes1
answer48
viewsHow to make a double filter on a long-format dataframe
I have a DF in long format with data from several countries. I would like to make a filter to fetch the last available value of the variable total_tests of each country, those without data are…
-
1
votes1
answer60
viewsHow to create numerical samples based on multiple conditions on multiple vectors?
Given the following data frame: df <- tibble::tribble( ~pass_id, ~km_ini, ~km_fin, 1L, 0.89, 2.39, 2L, 1.53, 3.03, 3L, 21.9, 23.4, 4L, 23.4, 24.9, 5L, 24, 25.5, 6L, 25.9, 27.4, 7L, 36.7, 38.2,…
-
1
votes1
answer70
viewsHow to change scales of a multifaceted graph in ggplot2
I have a graph composed of 27 subplots, each corresponding to a state, some states, such as SP and RJ have values much higher than other states and the scale of the graph is in larger intervals. Is…
-
1
votes1
answer25
viewsProblem using spread()
Hi, how are you? I’m having trouble using the function spread(): it shows error and does not pop. dados<-structure(list(V1 = structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
-
1
votes0
answers33
viewsWeb Scraping with R - static table
I would like to consolidate the data of a betting site in a database on R. I’m trying it the way below, but my script doesn’t recognize the columns and rows of the table in fact, only the layout:…
-
1
votes2
answers55
viewsTransform dataframe from long format to wide
I have a dataframe in long format and would like to transform it to wide format for exporting to Excel. I am using the function pivot_wider package tidyr, but the values are coming out this way: Man…
-
1
votes2
answers78
viewsTables type GT not printing inside loop in Rmarkdown
I’m programming a report generator that exports html. I use two files, the first is a loop that will determine the number of reports and within my template. Rmd I have another loop to print several…
-
1
votes2
answers43
viewsLeft_join returning dataframe with more lines than the original
I have a date.frame with IBGE census data and a column called IND and I have another date.frame with a column IND and another column NEW_IND. The column NEW_IND contains the new codes for the…
-
1
votes1
answer35
viewsI calculate in R, data value with the mean and standard deviation of the column
What I have to do is simple: take the value of the cell, subtract with the average of the values of the column, after dividing with the standard deviation of the values of the column. Example: Cell…
-
0
votes1
answer105
viewsFilter columns conditionally to another column
I would like to select a single value in the dataframe below, according to the following parameters: 1) The values in column nJRS would be the reference; 2) The value of the column nJRS should…
-
0
votes1
answer40
viewsHow to identify if one observation is in the same group as another?
I have a date.frame with the columns: cnpj_root, id_m_f, municipio and Uf I need to check the amount of cnpj_root that exists in each municipality and check if the matrix (1) is in the same…
-
0
votes1
answer27
viewsCompare line values in a data frame - R
I have a data frame with more than 1 million lines and I need to count the number of occurrences of a variable. However, the value found has to be inserted in a new "Qtde" column and the values have…
-
-2
votes1
answer297
viewsFilter with 2 variable conditions
I have two databases, the first one has about 30,000 lines the second 571. I need to filter the first with two conditions from the second bank. Condition A: fctr be == Condition B: date <= I…
-
-3
votes1
answer102
viewsA - Adding values with one condition
Good morning ! I have the DF below, I need to add the values of the accounts (columns with numbers) SEMESTER 1 with the 2 (if you have), by CNPJ and YEAR. Thus, I will have the total values of the…
-
-3
votes2
answers67
viewsHow to group by text [R]
I have a column in the dataset that has several variants of 5 options. I wanted to group based on what you have written in common. For example: coluna1 lapis vermelho grande lapis azul grande lapis…