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
-
4
votes1
answer175
viewsHow to loop to generate graphics in R?
Consider the following Data Frame: ITENS <-c("A","B","C","D","E") Q.1 <-c(10,20,10,40,10) Q.2 <-c(5,25,0,50,10) Q.3 <-c(15,20,5,40,10) Q.4 <-c(15,30,5,30,5) Q.5 <-c(20,25,5,20,15)…
-
4
votes2
answers101
viewsHow to make a loop/routine for the write.fst() function?
I have the following files in my working directory: Dados_1.fst Dados_2.fst Dados_3.fst Dados_4.fst ... Dados_10.fst The Dados_x.fst file (where x goes from 1 to 10) has the columns CODIGO,…
-
4
votes3
answers1583
viewsfunction in R that also returns the execution time itself
I know there is Rprof(), but it seems to me rather inaccurate compared to microbenchmark(). However, if I want to use the microbenchmark() I have to call the function 2 times, once to have her…
-
4
votes2
answers1017
viewsHow to insert a chart caption with two axes y in r?
As I insert the caption in this chart, like the bar would be the gross total and the line the net total? lines = 'Mes Acid Obt Jan 1450 102 Fev 1447 86 Mar 1461 87 Abr 1356 61 Mai 1398 80 Jun 1115…
-
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
votes3
answers488
viewsCalculation of Difference between Dates
I have the following DF: MATRICULA <- c('111','222','333','444','555') DATA_INICIO <- c('10/12/2017','31/12/2014', '30/06/2015','20/11/2016','01/04/2014') DATA_FIM <- c('10/12/2017',…
rasked 5 years, 11 months ago Bruno Avila 867 -
4
votes1
answer203
viewsR connection to Myqsl
Does anyone know how #Mysql can have access to a dataframe that was handled in R, I have already connected to the following script install.packages("RMySQL") install.packages("RJDBC") library(DBI)…
-
4
votes4
answers145
viewsHow to count strings from a variable
I have a variable in the database that’s like COMPOSIÇÃO DA COLIGAÇÃO : DS_COMPOSICAO DA COLIGACAO AVANTE / PDT / PODE / PMN AVANTE / PR / PV DC / PRTB / AVANTE / SOLIDARIEDADE / PRP / PATRI DC /…
rasked 5 years, 10 months ago Décio Vieira da Rocha 73 -
4
votes1
answer70
viewsGenerate multiple samples from the same vector
I’m a beginner in R. I’m trying to do a function to generate as many samples as possible without repeating size 4 taken from the same vector. I tried to loop the for, but I can’t do the whole thing.…
-
4
votes1
answer371
viewsHow to use letters instead of numbers within the LETTERS array?
The vector LETTERS works as follows: LETTERS[1:10] [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" Like adjust this vector to insert letters instead of numbers? Something like: LETTERS[A:J] Error:…
-
4
votes1
answer704
viewsHow to extract the week number of the month in R?
I’m having trouble extracting the week number of the month from a specific date. Example: hoje = Sys.Date() print(hoje) [1] "2019-02-11" In the example of the date above, hoje would be the 2nd week…
-
4
votes2
answers711
viewsIssue discriminant function constant - linear discriminant analysis [R]
How to issue the discriminant function constant (or constants, if multiple discriminant analysis)? Follows the dput for assistance in response. structure(list(REAÇÃO = structure(c(0, 1, 0, 0, 1, 0,…
-
4
votes2
answers250
viewsHow to select strings that start with a given word
I’m manipulating a dataframe on R v.3.5.2 and would like to know how I create a new variable called ES_1_4 which has only rows in the column Pathways which has the starting string as its value…
-
4
votes2
answers49
viewsPulling elements from one list to another under a R criterion
The vector below indicates the regressions I circled. regression_pairs=c("A~B", "C~D", "E~F", "G~H","I~J","K~L","M~N","O~P","Q~R") regression_pairs Below is the list where I saved the residuals of…
-
4
votes1
answer50
viewsJoin scattered values on different lines in the same line
Hello, I have a database in which I used tidyr::spread which resulted in information spread across several lines. I would like to join the different lines in one. Example: df <- data.frame(obs =…
rasked 5 years, 8 months ago Jessica Voigt 883 -
4
votes1
answer209
viewsRemove all before the first occurrence of a word gsub regex
This is so simple but I can’t find the answer! I would like to delete everything before the first occurrence of the word "that" in a string: What am I doing: v <- c("blabla que 1", "blabla que eu…
rasked 5 years, 8 months ago Jessica Voigt 883 -
4
votes1
answer49
viewsHow to change the cut point (cut-off) in glm function?
I have the segiunte database, where I intend to do a logistic regression: set.seed(1) dataset <- data.frame( x = replicate(6, runif(30, 20, 100)), y = as.factor(sample(0:1, 30, replace = TRUE)) )…
-
4
votes1
answer65
viewsError while executing nls in R - 'Arg' must be NULL or a Character vector
When I use the command n0 <- nls(Y~expo.der(x, A, B, C), data=dados_Indice, start=start, na.omit(NA), trace = TRUE) expo.der is the name of the created function that defines the formula used in…
-
4
votes1
answer93
viewsIncluding columns in a dataframe in R using a rule
This is my dataframe: df<-as.data.frame(matrix(rexp(200, rate=.1), ncol=10)) colnames(df)<-c("one","two","three","four","five","six","seven","eight","nine","ten") This is the entry I will use…
-
4
votes2
answers291
viewsConvert written numbers with thousands separator to numeric value in R
I have the following number that I am importing from a site, I put in the following way not to need to put all the import code of the data a <- as.character("353.636.000.000") I’d like to turn…
rasked 5 years, 6 months ago Henrique Faria de Oliveira 725 -
4
votes1
answer136
viewsCreating a dataframe based on two other dataframes using dplyr in R
These are my dataframes: df<- as.data.frame(matrix(rexp(200),, 25)) colnames(df)<-c("A","B","C","D","E","F","G","H","I","J", "K","L","M","N","O","P","Q","R","S","T", "U","V","X","Z","W")…
-
4
votes1
answer63
viewsHow to perform "sudo" commands between servers?
Before running a R script on server 'A' I have to restart Shiny-server on server 'B'. /bin/ssh cabala@***.***.***.*** 'sudo service shiny-server restart' I would like to enter a command into the R…
-
4
votes1
answer577
viewsHow to validate a CPF using a function in R?
I am trying to improve the code of @Rui Barradas that is posted here as a response, but it does not work for some situations. After debugging the code, I understand that the problem lies in the…
rasked 6 years, 1 month ago CARLOS FALCÃO 49 -
4
votes1
answer1104
viewsRun a file . R within another code in R
I have a code that reads the XML files that are in an enterprise network folder, and generates a file .RData. I have other codes that generate different reports for different sectors, using as a…
-
4
votes1
answer60
viewsA - Create control column from two other columns
Expensive, I have a very large database with the following feature: ORIENTAÇÃO VOTO Sim Sim Não Sim Sim Não Não Não I would like to create a third column in which if the values hit, 1 will appear.…
rasked 5 years, 4 months ago Guilherme Marques 89 -
4
votes1
answer1077
viewsExecution of multiple functions within loops *pply
dput: dataset=structure(list(var1 = c(93.6192987300456, 89.1180437617004, 73.1943506933749, 99.0350881963968, 32.3240431956947, 94.2517145164311, 53.7740966491401, 64.1642983071506, 83.643307145685,…
-
4
votes2
answers75
viewsSplit Column into Other Two Lat Long
I have the following datasheets: BIRDS.GENERO SP1 SP2 XLOCAL Thamnomanes caesius glaucus 0°32'S52°12'W Thamnomanes ardesiacus obidensis 0°10'S51°50'W Thamnomanes caesius glaucus 00°53'44"N52°00'08"W…
-
4
votes0
answers214
viewsDoes anyone know how to make a Web Scraping on the SICONV (Free Access) website - With R?
I’m trying to extract the information from the site of siconv dealing with covenants in R:…
-
4
votes1
answer1149
viewsHow to calculate percentage change with 3 variables in R
I have the following data: library(sidrar) Tab1612SojaQde <-get_sidra(1612,variable = 214, period = c("last"=22), geo="State",classific = 'c81', category = list(2713)) head(Tab1612SojaQde)…
-
4
votes0
answers130
viewsPowerbi Desktop and error with R (GGPLOT)
I’m really stuck and I need help. After installing R 3.5.1, I get this error message in the R views on the Power BI Desktop I was working on earlier. "Error: package or namespace load failed for…
-
4
votes1
answer146
viewshistrogram
good morning I would like to create a histogram with 26 species in the x-axis and the percentage of influence of commercial hunting in the reduction of each species (column 'depletion_rate') on the…
-
4
votes1
answer117
viewsProblems to plot graph with chartSeries function of the quantmod package from a data.frame to R
I’m having trouble plotting a Candlesticks chart from a file data.frame. Code example # Pacotes necessários ---------------------------------------------- library(BatchGetSymbols) library(quantmod)…
rasked 5 years, 11 months ago Henrique Faria de Oliveira 725 -
4
votes1
answer139
viewsPerform mutate in columns simultaneously
Hello, I have a dataframe where I want to apply the same function in several columns at the same time. I tried to use the dplyr::mutate_at but I don’t think I understand the logic of this operation.…
-
4
votes3
answers186
viewsRemove Environment (and list) elements based on their classes
Consider the vectors: a<-1:10 b<-1:10 c<-'a' d<-'a' e<-list('b') f<-list('b') g<-1.1 h<-1.1 The function below removes only one class (which is integer, in this case):…
-
4
votes1
answer202
viewsFunctional programming: applicability of parameters (.x) and (.) in purrr::map
I’m migrating to the package purrr, mainly in relation to the use of the function map. But I’m having a hard time understanding the concepts of functional programming in purrr. I would like to learn…
-
4
votes1
answer50
viewsHow to make a prediction interval for a restricted group?
Considering the model with only these two explanatory variables, indicate a 95% prediction interval for an individual in X1 first quartile (1st Qu) and X2 second quartile. I know the generic code,…
rasked 5 years, 10 months ago Gabriel Costa Pinto 43 -
4
votes1
answer150
viewsHow to transform an English standard date into a Brazilian standard date in R?
Suppose I have a date in the standard English format year-month-day (ymd): data = Sys.Date() print(data) [1] "2019-12-03" But I really need this date to be in the Brazilian standard day/month/year…
-
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
answer907
viewsWhen to use the.call function?
Dieferenmente de lapply, do.call applies a function across a list (which is also a data.frame). Consider the loop for down below: set.seed(123) for (i in 1:6) { assign(paste('var', i, sep = '_'),…
-
4
votes3
answers56
viewsHow to Capture a File Extension in R
I am having difficulty capturing the extension of imported files. I would like to extract the file extension and store in a variable. arquivo <- "dados/Inscritos.xls" extensao <- ?…
rasked 4 years, 7 months ago Michel Andrade 41 -
4
votes1
answer68
viewsError in nls: step factor 4.65661e-10 reduced below 'minFactor' of 9.31323e-10
I’m trying to run an analysis "nls", but the following error appears: "step factor 4.65661e-10 reduced below 'minFactor' of 9.31323e-10" I am using the following data sets and formula:…
rasked 4 years, 6 months ago Milton de Paula 305 -
4
votes1
answer1154
viewsHow to remove text from a string in a data frame column in r?
Hello! I have the following dataframe: Município (Código) Município Valor 2 1100015 Alta Floresta D'Oeste - RO 408765 3 1100023 Ariquemes - RO 477322 4 1100031 Cabixi - RO 126630 5 1100049 Cacoal -…
-
4
votes1
answer103
viewsStacked area chart
I’m trying to make an area chart according to the image below: But I’m using a different database than the one used for this graph and I’m having some questions: 1- I am using the following code:…
-
4
votes1
answer1043
viewsEncoding / Accents / Punctuation / R Markdown Symbols have gone
I have had a highly boring situation and the previous tutorials did not help. I recently switched computers, and now the R Markdown accents just got lost. Use windows 10 and the image file below is…
-
4
votes2
answers51
viewsSpecial character removal in Software R
in the database below in column 7 (Column title is Round) is written "1st Round". How to remove the "th" and keep only "1st Round"? Below follows the code for reading database view. url <-…
rasked 4 years, 2 months ago Filipe Fulgencio 49 -
4
votes3
answers49
viewsNormality and fragmentation of the sample
I’m having a problem with an analysis of shapiro.test in the R. I want to analyze the normality of a certain variable x, but I want to do this in stratified samples that together correspond to…
rasked 4 years, 1 month ago Matheus Peixoto 41 -
4
votes2
answers47
viewsIncrease the number of columns in the histogram
Hello, I’m having trouble increasing the number of columns in a histogram. I tried to change the number of Bins from 10 to 5 but it didn’t work. histograma: id MCP #MB02 12,59 #MB03 0,001 #MB04…
rasked 4 years ago Francielle Oliveira 71 -
4
votes1
answer114
viewsProblems in the covariance structure
Hi guys All right? I’m having some problems about defining the covariance structure in R. I need to adjust the following covariance matrices: AIR GUN compSymm Uniform. As you can see in the code…