Most voted "r" questions
R is an open-source environment and programming language for statistical computing, bioinformatics, and graphics. It is advisable to supplement your question with a minimum reproducible example.
Learn more…2,359 questions
Sort by count of
-
5
votes2
answers130
viewsR - cut digits
Would someone like to tell me how I can cut digits in the R? Example: ano <- c(1999,2000,2001,2002,2003) And only to return: #[1] 99 00 01 02 03…
-
5
votes1
answer181
viewsHow to parallelize on multiple levels in R?
I’ve been researching how to parallelize for in R and found the package foreach, which, from what I understand and correct me if I’m wrong, replaces the for as follows: library(foreach) vetor <-…
-
5
votes1
answer82
viewsSelect the dataframe with the highest number of rows in a R-list
Hello, I am drawing a loop and at a certain precise moment select the dataframe with the highest number of lines within a list. Example: df1 <- data.frame(a = 1:15) df2 <- data.frame(b = 1:35)…
rasked 5 years, 9 months ago Jessica Voigt 883 -
5
votes1
answer1144
viewsHow to train a decision tree in R?
Let’s say I have the following data sets. set.seed(123) n <- nrow(iris) indices <- sample(n, n * 0.8) treino <- iris[indices, ] teste <- iris[-indices, ] How could I use the R to train a…
-
5
votes2
answers96
viewsConvert a list with different line dataframes into independent dataframes
I have a list with 3 dataframes, which derive from the function split: > split $`1` bin group1 group2 missing score1 score2 gender size score3 income city 0 1 1 NA 3 2 M S 4 1605.525 San…
-
5
votes1
answer60
viewsChange colors on the chart
Good afternoon. How do I assign different colors to each line and how to red the part of the chart above the top line and below the bottom line? a<-c(5.8, 9.8, 2.4, 4.4, 4.6, 5.6, 5.6, 7.4, 6.6,…
rasked 5 years, 7 months ago Vitor Hugo 151 -
5
votes1
answer51
viewsHow to store the password in the R script in the package 'Encryptr'?
I did it: library(encryptr) genkeys() And I created the password: 0)]30l^8 password<-"0)]30l^8" data(gp) write.csv(gp, "gp.csv") encrypt_file("gp.csv") My problem: How to automatically enter the…
-
5
votes1
answer204
viewsDownload zip files from a link to a PC folder via R
Good afternoon I need to download the zip files from the following site ftp://ftp.bmf.com.br/MarketData/ I would like to download via R, and that the files were saved on my computer, but I do not…
rasked 5 years, 6 months ago Henrique Faria de Oliveira 725 -
5
votes1
answer410
viewsDownload a table from a website in data.frame format in R
Good night I need to download the table entitled Fundamentalist indicators at the following link http://www.fundamentus.com.br/detalhes.php?papel=PETR4 I intend to download all the assets of the…
rasked 5 years, 6 months ago Henrique Faria de Oliveira 725 -
5
votes2
answers200
viewsHow to create a Stopwords using R
Hi, I need to do a task and I’m not getting into a logical reasoning. My scenario is: I have a DF with several columns, I need to "read column 3", identify the words and sort. Example: DF nome rua…
-
5
votes1
answer384
viewsError: In Ops.factor
I’m working with a weather data.frame and I want to know if the data is within the reading limits of the equipment. For this purpose the tolerance limits adopted for temperature (temp_med, temp_max…
rasked 6 years, 1 month ago Luana Tavares 51 -
5
votes1
answer117
viewsLoop Error in R
I created this loop: library(forecast) a=1 b=60 while(b<=(NROW(tsarroz))){ janela=dput(tsarroz [a:b]) serie=ts(janela,freq=6) HW=HoltWinters(serie) prev=forecast(HW,6)…
-
5
votes1
answer452
viewsbar graph ggplot 2 vectors side by side
Can anyone tell me if it is possible to make this chart with the bars side by side without using data frames or "melt"? v1=c(100,120,140) v2=c(125, 102,104) a=data.frame(year=factor(2003:2005))…
-
5
votes1
answer59
viewsDoubt how to measure the number of words between two specific words in a string in R
Hello, People! I’m working on a function in R that measures the amount of words between two specific words, I’m calling the function worDistance, it works as follows, you insert two arguments, given…
rasked 6 years ago Henry Gonçalves 53 -
5
votes1
answer50
viewsProblem creating a data.frame
I want to export several results to excel and for that I need to first leave them in the ideal format, but I am facing problems because I want them to be stacked in a single column. This is an…
-
5
votes2
answers1147
viewsColor scale adjustment on R
Good afternoon, I created a bar chart using an indicator to fill the colors of the bars, where the nearest red is bad, and the nearest green is good. It turns out that it adjusted according to the…
-
5
votes2
answers85
viewsRepeating the subtraction of groups in a data frame for all numerical variables
I have the following code: df <- data.frame(grp = rep(letters[1:3], each = 2), index = rep(1:2, times = 3), value = seq(10, 60, length.out = 6), value2 = seq(20, 70, length.out = 6), value3 =…
-
5
votes2
answers1524
viewsChange <Chr> to number in R
My dear, I am trying to convert the data of columns 4 and 5 to number, but you are giving this error. Any suggestions? Thanks in advance! library(tidyverse) dadosarrumados <- data_frame( Região =…
rasked 5 years, 11 months ago Fabiano Meira 59 -
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…
-
5
votes3
answers115
viewsRegular expression of citations in R
I would like to extract all reference keys I use in a document markdown beginning with the character @. Here is an example of the different ways I can quote a document using this key: line <-…
-
5
votes3
answers969
viewsDifferences and similarities between apply and for loop functions
I have this list: dataset<-data.frame(matrix(runif(6*30,20,100),ncol=6)) cluster<-kmeans(dataset,centers=3) cluster dataset$kmeans<-as.factor(cluster[['cluster']])…
-
5
votes1
answer144
viewsItalics in dashboard headings in facet_wrap()
I’m having trouble formatting species names in italics in the title of the panels with the argument facet_wrap in the ggplot2. Following example: library(ggplot2) ggplot(mpg, aes(x=displ, y=hwy)) +…
-
5
votes4
answers4136
viewsCount equal values in one data frame and store in another in R
I need to count the equal values of a column in a data frame (database with the total name) and store the total in a column of another data frame (database with the unique name) that contains the…
-
5
votes2
answers186
viewsWhat is the use of the ".Random.Seed" vector?
I realized that in the r there is a hidden vector in the globalenv(), called .Random.seed. Even with the globalenv() with no object, .Random.seed is still available when using the function ls with…
-
5
votes2
answers661
viewsHow to transform the class of a "factor" column into "date" within a data.frame?
I have a base extracted in csv (dados_base), with the period from Dec/2017 to Jan/2019, which has three columns: USUARIO, DT_PAGTO and VL_PED_PG, where the first field represents users with the…
-
5
votes1
answer79
viewsHow do I get a value from a cell in R?
I imported my data that was in a spreadsheet from Excel to the R, by placing them in a variable called umParticipante. However, when I make the following code: umParticipante.nome <-…
-
5
votes1
answer410
viewsR - How to calculate the density from the accumulated curve based on the Cox regression model
I calculated the accumulated probability (cdf) of my data, based on the probability of exceedance (Edf), using the Cox regression model. So far ok, no problem at all. However, does anyone know if…
-
5
votes3
answers673
viewsHow to go through the data.frame cases using `dplyr`?
I am trying to analyze the cases (lines) of a data.frame with dplyr, but without success. I created two functions for this: f1 <- function(x) { c(s = sum(x), m = mean(x), v = var(x)) } f2 <-…
-
5
votes1
answer423
viewsWhat is the use of arrays in r?
vector, matrix, data.frame and list are widely used in data analysis and tag peguntas r here in the website. In particular, I see no applicability of array in r. For example: vec_1 <- c(2:4)…
-
5
votes2
answers59
viewsHow does R calculate the following code?
2 + 2 %>% sqrt() Because the result is not 2, but 3.4142?
-
5
votes1
answer204
viewsR how to calculate on different lines of the date.
I’m doing it this way: temp <- data.frame(ano = c(1997,1999,2001,2003,2005,2007,2009,2013,2019)) a <- (temp[2,1]-temp[1,1])+1 b <- (temp[3,1]-temp[1,1])+1 c <- (temp[4,1]-temp[1,1])+1 d…
-
5
votes1
answer620
viewsHow to set a decimal display pattern in R?
I have a rmarkdown script that generates a report in . pdf. I would like to standardize the number of decimal places displayed, without needing to round() in every function. At the beginning of the…
-
5
votes1
answer84
viewsHow to select samples in R
How to select 100 size samples n = 10, without replacement, using a population of N = 1000? My population: set.seed(1234) x <- rnorm(1000, mean = 100, sd = 20)…
rasked 4 years, 1 month ago Alice Ramos 53 -
5
votes3
answers64
viewsObtaining single records based on two columns
Considering the dataframe df1 intended to obtain a dataframe with unique records (origin, destination) counting the number of unique pairs (origin, destination) and summing the value per unique…
rasked 3 years, 3 months ago user250908 77 -
5
votes2
answers104
viewsR straight location of x in y
I have this doubt, but honestly I do not know if the solution really exists in R. I have a graph x/y, and I want to draw two lines, (1) from the x-axis to the die and another (2) from the y-axis to…
-
5
votes1
answer57
views -
5
votes1
answer125
viewsFormatting Titles in Table of Contents Rmarkdown (R)
That’s my code in Rmarkdown: --- title: "Formatando Table of Contents" author: "Laura" date: "`r Sys.Date()`" output: pagedown::html_paged: toc: true toc_depth: 3 self_contained: false --- #…
-
5
votes0
answers49
viewsConsider return routes in the same way
I’m having trouble coding the variable rota in the R so that it assumes a unique value when the route is the same, independent of the point of origin (first 4 characters of the route variable) and…
-
5
votes1
answer298
viewsCompare objects in R
I have two dataframes: atualizada PIMPF_Br_A_1_sa PIMPF_Br_A_2_sa 1995-01-01 74.35501 35.59109 1995-02-01 74.06131 35.43400 1995-03-01 74.06131 35.93259 and: atualizada PIMPF_Br_A_1_sa…
-
5
votes1
answer71
viewsHow to create a heatmap for a calendar?
One of the graphs I find most interesting is called, in English, heatmap Calendar. Perhaps its most common application is in github, that displays our collaborations in the last year with the chart…
-
5
votes2
answers321
viewsHow to plot map with place names - ggplot - R
I downloaded the data and plotted a map with the demographic density of the cities of the Metropolitan Region of São Paulo. But it is difficult to identify the cities. rmsp <- readOGR("rmsp",…
-
5
votes2
answers1104
viewsHow to eliminate variables that have some NA values in R
Currently I have a data frame with textual and numerical variables. However, some variables have NA in just a few observations, not all. For example, I have the following data frame Cidade Estado…
rasked 4 years, 7 months ago Lucas Azevedo 59 -
5
votes1
answer109
views -
5
votes1
answer82
viewsR - Function to generate graphs and change axes
I need to display four charts several times in a Rmarkdown report. So I decided to create a function to plot the graphs. It was like this: gera_graficos <- function(base,var1,var2){ hist1 <-…
-
5
votes2
answers333
viewsLabels for Plot box in ggplot2
I have this graph created by the function geom_boxplot. Would you like to label each boxplot correctly. What am I doing wrong? I am using the wrong factor?…
-
5
votes1
answer62
views'The number of derivatives returned by func() (2) must Equal the length of the initial conditions vector (4)' in R
I’m using ode, package deSolve to solve an R ED system, but I get the error: Error in checkFunc(Func2, times, y, rho) : The number of derivatives returned by func() (2) must equal the length of the…
-
5
votes2
answers98
viewsConvert "2012-01-01" to "2012-Jan-01" in R
good morning. It’s my first post here. I just started my journey in "R" and I’m having a hard time with dates. I even managed to get to the result I wanted, however I took a turn, in my view, VERY…
-
5
votes1
answer72
viewsInclusion x-axis name of months
I am not able to change/include in the x-axis the information of months in the nominal format. Dice: dt;AverageTemperature;Month;Year;media_tempMes; 1846-01-01;26.499;1;1846;25.5466;…
-
5
votes1
answer62
viewsThere are ways to add figures on a Plot in R
Gero this figure: when using that code: library(tidyverse) library(plotly) tres <- readRDS(…
-
5
votes2
answers50
viewsHow to relate a column to a dictionary in R?
library(tidyverse) I have a dataset that has in one column titles of articles and in another column, their respective authors. I reproduce here a row of this dataset: df<-tibble( titulo= "A…