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
-
3
votes2
answers94
viewsDifferent Records
I have two tables: MATRICULA_A <-c(123,234,345,456) dados_1 <- data.frame(MATRICULA_A) MATRICULA_A <-c(345,456,111,222,333,444) dados_2 <- data.frame(MATRICULA_A) I need to extract only…
-
3
votes1
answer182
viewsLower Value of a Set of Columns
I have a set of data and would like to select only the smallest value among each primary key. Follow the example of my DF: ORDEM <- c(1,5,2,3,1,10) GUIA <-…
-
3
votes0
answers53
viewsRead and view Polsar images (Large amount of data)
I would like to know if you know any method for reading and viewing images that have a large amount of data and that it is not possible to load everything in RAM (+- 20 GB)I could see and think of…
-
3
votes1
answer109
viewsCopying files with the same name to a directory without overwriting (R!)
Hello, I have a problem. I have a dummy directory that contains a set of folders, each folder within itself contains a protocol folder, and within each folder I have one or more files. Ex: Pasta…
rasked 6 years, 5 months ago Jessica Voigt 883 -
3
votes1
answer248
viewsOSMAR library (Openstreetmap) error
Hello, I’m trying to use the OSMAR library in R to plot routes and I’m not getting it. library(osmar) library(leaflet) library(igraph) src <- osmsource_api() get_osm(node(18961430), source = src)…
rasked 6 years, 5 months ago Lucas Freitas 145 -
3
votes2
answers114
viewsHow to create one vector from another in r?
I need to create the vector fixo of NA and 0 from another vector coef. If coef<-c(1,4,10) then fixo = (NA,0,0,NA,0,0,0,0,0,NA) I tried to use str_detect: num<-c(1,4,10) maiorn <- max(num)…
-
3
votes1
answer611
viewsA - How to create a delayed variable (lag) conditioned to the individual?
I need to delay a variable from my db (dCoopCred). However, it cannot mix the delay of two individuals (CNPJ). I would like that LAG_Result_ant_desp were Result_ant_desp in t-1 (previous period).…
-
3
votes1
answer67
viewsHow do I adjust the lengenda to Spatial Lines in ggplot?
I’m filling lines on polygons, but when I try to insert the caption the lines get bad, how do I adjust it? Without the Legend library("ggplot2") ggplot(mapa_mg) + aes(x=long, y=lat, group=group) +…
-
3
votes0
answers760
viewsHow to change colors of ggplot chart?
The code below generates a graph of lines whose colors are automatically set to blue and red: ggplot(aes(x = factor(year), y1 = auto_course_choice, y2 = auto_hire, group=country)) + geom_line(aes(y…
-
3
votes2
answers1338
viewsr - sum of a variable relative to the values of another variable in a data frame
I have a multi-column dataframe. How do I add the values of a column within an element of another variable? I want to do this to summarize the data of each species within each campaign. I tried to…
-
3
votes1
answer77
viewsHow to change a value in a list of R files?
I have a list of files, example 001.R and 002.R. Usually I do: for (i in c('001.R' e '002.R')){source(i)} However, there is now a parameter within each file that I need to change. No 001.R and 002.R…
-
3
votes1
answer248
viewsBreaking lines in colnames or rownames
This is an example of a report that I’m doing. As the margin settings are already adjusted, when I change the names of the columns with the colnames it ends up passing the margin. Any help on how to…
-
3
votes3
answers2296
viewsHow to format a "date" column inside of a data.frame in R?
I’m having trouble formatting a column with dates in my database. Example: 01/08/2018 06:02:44 I would like to format the column by removing the team and in another column indicate the corresponding…
-
3
votes1
answer309
viewsR Delete data frame lines by condition
I have the following data set: Nome <- c("Laetia","Vouacapoua","Lecythis","Pourouma","Poraqueiba","Pseudopiptadenia", "Abarema"); I1 <- c(1,3,3,2,3,3,3); I2 <- c(1,3,1,3,3,3,3); I3 <-…
-
3
votes0
answers185
viewsVisual Studio Code does not recognize Rscript
Hello. I installed VS Code 1.31. I do not understand why the editor is not recognizing Rscript in "output", since in "terminal", it is recognizing R. Follow the code in Settings.json. What I can’t…
-
3
votes2
answers117
viewsturn numbers into relative frequency
Dear, I have the following table with absolute numbers: structure( list( X = c("Ver_suj", "Ver_obj", "Substantivo", "Adjetivo" ), Bolsonaro = c(59L, 299L, 988L, 653L), Ciro = c(188L, 242L, 128L,…
-
3
votes1
answer223
viewsWidget in Shiny to take a file path
In an application here from work I use the widget below for the user to load a database and it is 'criticized' by another script. fileInput("file1", "Escolha o arquivo", multiple = FALSE, accept =…
-
3
votes1
answer110
viewsCorrplot - How to adjust to the center in Rstudio?
How do I display the center-adjusted corrplot? When executing the command in Rstudio, the graph is displayed very small and positioned to the lower right. corrplot(cor.matrix, method="circle")…
-
3
votes1
answer37
viewsBarchart commands for R software
How do I use some commands like font.main, col.main inside the command barchart package lattice. I’m trying to use these commands and they’re not working.…
rasked 5 years, 8 months ago Vitor Hugo 151 -
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
votes1
answer48
viewsLapply to pull ADF test results on R
This is my list: mylist=dput(mylist) list(list(c(30, 50, 35, 25, 45), c(40, 35, 35, 50, 45), c(40, 20, 40, 50, 25), c(35, 45, 45, 45, 40), c(20, 30, 50, 45, 20), c(40, 40, 50, 30, 40)), list(c(50,…
-
3
votes1
answer47
viewsPoorly calculated coefficients in Linear Regression in R due to NA s
This is my dataframe: structure(list(Year = c(1979L, 1979L, 1979L, 1980L, 1980L, 1980L, 1981L, 1981L, 1981L, 1982L, 1982L, 1982L, 1983L, 1983L, 1983L, 1984L, 1984L, 1984L, 1985L, 1985L, 1985L,…
-
3
votes1
answer62
viewsPresenting tabulated linear regression result
This is the matrix with the results of my regression models: linear_models=structure(c(-0.9051, 2.0445, 0.0075, 0, -3.9959, 7.4458, 0, 0, -0.0666, 0.4933, 0.8627, 0.4268), .Dim = c(2L, 6L),…
-
3
votes1
answer44
viewsFilling lines with correct data in R, joining successive lines
I have a database with the second structure: a=as.data.frame(tribble( ~a, ~texto, ~x2007, ~x2008, "a","aa",0,0, 0,"--",12,13, "b","bb",1,2, "c","cc", 0, 0, 0,"dd", 0,0, 0,"ee",7,8)) The rows…
-
3
votes2
answers117
viewsI could not resolve the error: The condition has length > 1 and only the first element will be used
I know there are other questions about this mistake, but since I’m a beginner they didn’t help me solve my specific problem. I am working on the following date.frame: structure(list(Dates =…
-
3
votes4
answers1772
viewsError installing xlsx package
I need to write files that are in xlsx format, a package option that does this is xlsx, but when I went to install it appeared the following error: require(xlsx) Carregando pacotes exigidos: xlsx…
rasked 5 years, 8 months ago Pesquisador008 59 -
3
votes1
answer369
views -
3
votes1
answer143
viewsOptimization of R code
I wonder if anyone has any suggestions so I can optimize the code below. The idea I took from that website. You have a permutation of n cards, for example [2, 4, 1, 3] (where the 2 is the top card).…
rasked 6 years, 2 months ago Rafael Cunha 4,954 -
3
votes1
answer44
viewsHow to verify the presence of each element of a vector, line by line in a matrix in R?
Suppose I have a vector that goes from 1 to 10. I want to check binary for each element of the vector if it is present in the matrix line, being 0 for no presence and 1 for presence, regardless of…
rasked 5 years, 7 months ago pinheiiro arthur 31 -
3
votes2
answers104
viewsApproximate graphics
How do I approximate the graphics generated by the following command? par(mfrow=c(2,2)) barplot(1:4) barplot(1:4) barplot(1:4) barplot(1:4)
rasked 5 years, 7 months ago Vitor Hugo 151 -
3
votes1
answer192
viewsHow to improve R output
Is there a package or way to make more visual the output of regressions in R? Something that leaves information more organized, similar to Stata and E-views.
-
3
votes1
answer156
viewsConditional Operations Error in R
I am programming a simple recursive algorithm to compute the Fibonacci sequence in R, as I do in C. Follow the same below: fibonacci <- function (n) { if (n == 1L) return (0L) else if (n == 2L ||…
-
3
votes1
answer47
viewsProblem organizing a tidyr dataframe in R
I have this dataframe and I need to organize it so that the single dates are the first column and the columns are the shares of Bovespa with their values being their respective prices:…
-
3
votes2
answers233
viewsHow do I chart the production function of Cobb-Douglas in the R?
I would like to draw up the graph for the Cobb-Douglas production function in the R,: P(L, K) = 1,01L 0,75 k 0,25 Where L and K vary between 0 and 300.
-
3
votes1
answer36
viewsHow to create a command to choose linearization alternatives
I have the following command to obtain coefficients for linearization of the Michaelis Menten function. # "Estimativas para "CHUTE" # 1 para (Eadie-Hofstee y = -B(y/x) + A)(Especialmente para RMSEA…
-
3
votes1
answer328
viewsStopword does not work
Hello, I made the program that serves to do basic text preprocessing to use in Mining text tools. It must be something very trivial, but I can’t see where it could be wrong.…
-
3
votes1
answer349
viewsR corrplot - coloring based on correlation values
I have a binary dataframe (53115 Rows; 520 columns) and I want to make a correlation graph. I want to color the correlation values to red if they are greater than or equal to 0.95, if contracted, to…
rasked 6 years, 1 month ago Isabelinho 41 -
3
votes2
answers290
viewsCreate a bar graph in ggplot2 with juxtaposed columns
I would like to create a bar chart on ggplot2 with x1 and x2 side by side comparing month to month. I tried the following code, but was unsuccessful: Mean_2013 <-…
-
3
votes3
answers5381
viewsHow to replace variables with NA values with ZERO within a date.frame in R?
Let’s say I have a 6x5 data.frame, for example: print(Dados) Linha A B C D E L1 4 3 NA 2 4 L2 1 NA 1 NA 1 L3 NA NA 2 3 4 L4 2 4 5 NA 9 But I want to replace the "NA" values of the data.frame with…
rasked 5 years, 6 months ago Izak Mandrak 1,059 -
3
votes1
answer369
viewsHow to run str_detect (stringr) for more than one variable and at once?
I want to filter my database based on two variables: via and city. This filter, however, is made by means of particles of cases present in these two variables. For example, I want to analyze who…
-
3
votes1
answer64
viewsLoop command to group values from a database into a new list
Good afternoon, everyone! I’m starting in R (starting well) and tried to make a script to solve a simple operation that, however, was performed entirely in excel during a mini-course I did, giving a…
-
3
votes1
answer92
viewsHow to delete elements from the list through a condition?
I used the following function: splitfile<-split(training,list(training$group1,training$city)) and this gives me a list of dataframes with different lines, based on the variables I selected.…
-
3
votes1
answer523
viewsHow to create dummy variables
I’m trying to turn every variable in my database into dummy variables: >dados X1 X2 X3 1 1 3 1 2 3 2 1 3 3 2 1 4 2 3 2 5 2 3 3 I’m trying to create binary vectors for this. But, I can’t do it the…
rasked 6 years ago user129518 -
3
votes1
answer89
viewsSplit data frame by the first line itself
I’m trying to create an index number from a data frame. I would like to divide each column by the first number without having to do the division column by column. Just as an example, df would be:…
-
3
votes1
answer304
viewsReading data from PNAD 2016
When reading the Pnad 2016, I executed the code below, in r studio # Ler o dicionário de variáveis com as posições #devtools::install_github("tidyverse/readr") library(readxl) library(dplyr)…
rasked 6 years ago Danielle Duarte 31 -
3
votes1
answer387
viewsSubtract rows from a group in a data frame by another group
Assuming the following example: set.seed(1234) df=data.frame(grupo=rep(c("A1","A1.2","C","D"), 3), ano=c(rep(2007,4),rep(2008,4),rep(2009,4)), valor1=sample.int(100,12), valor2=sample(20,12),…
-
3
votes1
answer118
viewsCluster analysis by groups
I’m trying an analysis of cluster for several groups within a dataframe, with the aim of returning the characteristics of this analysis (ex. the resulting groups) in a database through the function…
-
3
votes1
answer656
viewsHow to put percentage in bar graph?
I’m not getting a percentage of the bar chart below. I wonder if anyone can help me. dado <- data.frame("Estado" =c("ALESP", "ALRS", "ALMG"), "teste" =c(9, 29,20)) library(ggplot2) ggplot(dado,…
-
3
votes3
answers433
viewsgeom_text positioning labels individually
I’m making a chart similar to this one in the example, where I position the labels by group: I’m using the code: set.seed(1000) ano=factor(rep(1996:2016,2)) cod=c(rep("K1",21),rep("O1.3",21))…
-
3
votes2
answers91
viewsExtract information from a string
I have the following string I would like to extract only prices within that string thank you in advance a<- " Scarpin Sofia Salto Bloco Slingback TurtleR$269,90 Scarpin Sofia Nobuck Salto Bloco…