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
-
7
votes2
answers3321
viewsConvert Character Frame Data Column to Numeric
When trying to convert the text values of a column data.frame, created using Stringasfactor = FALSE, in numerical terms, I obtained an abnormal result by coercion: > str(ccredito$Restaurantes)…
-
7
votes2
answers87
viewsSomatoria accumulating columns in a Matrix in R
I have the following situation : In a numeric type Matrix : Temp <- matrix(runif(25, 10, 100),nrow=5,ncol=5) V1 V2 V3 V4 V5 11 34 45 54 55 16 21 45 75 61 88 49 85 21 22 12 13 12 11 10 69 45 75 78…
-
7
votes3
answers22504
viewsHow to change the name of a column
I have a date.frame, I changed the data class of the date column and later I separated the other three column through the Separate command, whose names became %Y, %m and %d, I would like to change…
rasked 8 years, 6 months ago Fabiane Pereira 113 -
7
votes1
answer392
viewsHow to use %<> % operator in R
What the operator means %<>% in r ? What is your difference from <- ? Under what circumstances can it be useful?
-
7
votes1
answer83
viewsHow to use contents of an array to mount the name of a file to be saved?
I’ve tried to use colnames(), names() and nothing works. My data is something like that (however, I have 38,000 names and 38,000 columns): nomes <- c("nome105", "outro.nome_26", "qualquerCoisa")…
-
7
votes1
answer647
viewsChange facet_wrap order in ggplot2
See the code below, which generates the graph that comes soon after: library(lme4) library(ggplot2) ggplot(sleepstudy, aes(x=Days, y=Reaction)) + geom_point() + geom_smooth(method = "lm", se=FALSE,…
-
7
votes1
answer235
viewsPlot 3D figures for list data
I have a list a with three matrices and one vector v with any three frequencies (positive reals), these matrices form triangles through a function I created pplot. I wish to add vector information v…
-
7
votes2
answers190
viewsEdit the style of the external div tag of a box in Shiny
I’m developing an app on R’s Shiny, and I’m having trouble editing the tag out of a box. When I turn the remote: box( title = 'Teste', width = 4 ) the corresponding HTML it creates is: <div…
-
7
votes4
answers1920
viewsCreate column with sum and percentage of the maximum of other columns
i am a beginner in the R language and wanted to know how I create a function mutate that creates a new column in my table and at the same time store in this new column the sum of the values…
-
7
votes1
answer398
viewsFind the last day of the month
At the beginning of the month I always need to calculate the age of people within a certain database. I always consider the last date of that month, for example: in September I calculated the age…
-
7
votes2
answers604
viewsPDF to text organizing columns
I am scraping to extract files .pdf, and I need these files as an organized text, since for each line of text in the file there are 3 different columns. For example in this file, you can see the 3…
-
7
votes1
answer143
viewsBuilding new variables using dplyr
I have the following database Clientes.Dep..Gratuito.PCG Clientes.Dep..Gratuito Clientes.Dep..Não.Gratuito 0 0 0 0 0 0 25 0 0 0 0 2 0 0 79 0 0 71 Clientes.Usu..Gratuito.PCG Clientes.Usu..Gratuito…
-
7
votes1
answer1340
viewsCalculate Time Difference in R
I have two dates in date and time format. Data1 <- 20/01/2018 20:33:58 Data2 <- 21/01/2018 20:23:48 The difference in hours is 23:49:50. How is the calculation of this difference in R? Also, I…
rasked 6 years, 8 months ago Bruno Avila 867 -
7
votes1
answer213
views -
7
votes1
answer204
viewsExport data from Google Sheets to R
Hey, guys, what’s up? I’m a beginner in R and I have a question: It is possible, and if possible, which is the way to export data from a table of google Sheets (or Drive) to R. There is some library…
-
7
votes2
answers408
viewsBuilder and inheritance in R
It is a theoretical question, but it may help to understand a little the logic of programming in r. What it is and how it works builder in the language r? What is its use? What it is and how it…
-
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
answers4121
viewsR - Map of Brazilian cities
Good morning, I’m trying to create a Brazilian map that presents the amount of cooperatives present in each city. I have a table with the IBGE code of the municipalities and the amount of Coop. I…
-
7
votes2
answers504
viewsReplace ")" by space using str_replace_all() in R
I got the following data.frame: cadastros <- data.frame( email = c('[email protected]', '[email protected]', '[email protected]', '[email protected]'), telefone = c('(61)99831-9482',…
-
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…
-
7
votes4
answers315
viewsHow to apply several functions to the same object?
How is it possible, in the R, apply several functions to the same object? Example: Let’s say I have a vector x. set.seed(123) x <- rnorm(10) x # [1] -0.56047565 -0.23017749 1.55870831 0.07050839…
-
7
votes1
answer265
viewsmake Sankey diagram with two-way links R
I have the following data I use to make the Sankey diagram: list(nodes = structure(list(name = c("1.1.1. Formação Florestal", "1.1.2. Formação Savanica", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,…
-
6
votes3
answers17265
viewsHow to sort a column-by-column data.frame in R?
Suppose a data.frame with numerical values and strings: set.seed(1) dados <- data.frame(w=rep(c("A", "B"), 2), x= rep(c("D", "C"), 2), y= rnorm(4), z=rnorm(4), stringsAsFactors=FALSE) dados w x y…
-
6
votes1
answer829
viewsR workflow: strategies to organize a data analysis project
Based on this question from the SOEN, ask: What strategies do you recommend to organize a data analysis project on R? The project usually involves the following steps (not necessarily in that…
-
6
votes2
answers443
viewsReorder categories in a data frame
When we import data into R it sorts the categories alphabetically. How to change this order? Suppose these are the following data: df <- data.frame(categorias=c("Muito…
-
6
votes1
answer5017
viewsExport formatted R to Excel data
Suppose a data.frame like this: tabela <- structure(list(vendedor = structure(1:4, .Label = c("A", "B", "C", "D"), class = "factor"), Total = c(3300, 440, 1020, 200)), .Names = c("vendedor",…
-
6
votes5
answers14983
viewsHow to merge multiple dates frames into one
I want to create a data frame as a junction of 4 other data frames. I was able to do this using such commands: ZHO<-as.data.frame.matrix(zho) ZHO ZES<-as.data.frame.matrix(zes) ZES…
-
6
votes2
answers446
viewsFunction using as arguments successive values of a column (R)
I have a data.frame with 13 columns and 78 rows. I need to do it for each column ((x1/x2)^12)-1, being x1 the value in the first row of the first column, x2 the value contained in the second row of…
-
6
votes1
answer1449
views -
6
votes2
answers816
viewsR - IBGE municipal data download
Is there any way to download municipal IBGE data with R command line?
-
6
votes2
answers381
viewsCreate new matrix from a fairly large first efficiently
Guys, in R, I have a very large database and want to create new columns. I will try to explain my problem with a very small matrix. Next, "1" means private school and "2", publishes. I have for…
-
6
votes1
answer1320
viewsrbind error: "Error in match.Names(clabs, Names(xi))"
I’m trying to build a function that counts the number of complete cases in files. csv (data frames), ie the number of lines with values (and not "NA"). The function I wrote can read the file(s)…
-
6
votes2
answers441
viewsHow to make a "rbind" in tables of an SQL base from R?
I would like to "merge" two tables of a Sqlite "database" from the R -- and save it to a new table within the same database. Below, I send a minimum reproducible code:…
-
6
votes1
answer1707
viewsHow to Label Distributions in ggplot
I have the following graph of the exponential distribution, I want to put a caption showing which parameter of my exponential. ggplot(data.frame(x=c(0,5)),aes(x))+…
-
6
votes2
answers202
viewsdata.frame hierarchy for nested list in R
I got the following data.frame d: x <- data.frame(a=letters[1:3], b=letters[4:6], c=letters[7:9], stringsAsFactors=F) d <- tidyr::expand(x) d Source: local data frame [27 x 3] a b c 1 a d g 2…
rasked 9 years, 10 months ago Julio Trecenti 987 -
6
votes2
answers871
viewsHow to decode many columns of a R data frame
I have a data frame with more than 300 columns that are categorical but are encoded as numerical. Each of these columns has its own "type", that is, it has its own encoding table. My problem is to…
rasked 9 years, 7 months ago Roger Salvini 61 -
6
votes1
answer22729
viewsHow do I export table in R in txt or csv?
I wonder how I do to export a generated data table within the R to format txt or csv?
-
6
votes2
answers3041
viewsHow to separate the characters of a string in R?
I have values a string containing a date "01/01/2000" I want to separate the day, month and year. #Data #01/01/2000 be it #Dia Mês Ano #01 01 2000 How do I do it in R?…
-
6
votes1
answer117
viewsHow to export a polygon created by drawPoly as shapefile?
I created a shape using the function drawPoly() (bundle raster) that draws the polygon manually. At the end of the selection it generates a SpatialPolygon, but I can’t export because I’m not a…
rasked 9 years ago Vivian Ribeiro 195 -
6
votes1
answer91
viewsHow to position text in the intermediate columns?
Hello, I generated a column chart that is composed of 15 groups of 3 columns (each group of 3 refers to a patient in 3 distinct times) and would like to identify each patient by placing a text…
rasked 8 years, 11 months ago Luís Muniz 163 -
6
votes1
answer4170
viewsHow to draw elements (select elements randomly) from an array?
How can I draw elements (select elements randomly) from a vector in the R? For example, I want to draw elements from this vector: numeros = c(1,2,45,63,29,100,999,23.45,76.1)…
rasked 8 years, 11 months ago Capitão Ahab 565 -
6
votes2
answers57
viewsA: problems with Sort (NA)
I have a vector I want to order using sort but, in doing so, I do not see the missing values (NA). How to do it? Grateful. > x [1] "b" "c" "a" NA NA "b" "c" "a" NA NA "b" "c" "a" > sort(x) [1]…
-
6
votes2
answers940
viewsFilter 5GB CSV file on R
I am trying in every way to tamper with a 5GB file for my monograph. The code I’m trying to get into is as follows:: > write.csv(subset(read.csv("enem.csv", header=TRUE), UF_ESC=="SP"),…
rasked 8 years, 10 months ago André Oliveira 376 -
6
votes2
answers1558
viewsHow to know the day of the week in R?
Is there a package or function in R that allows to easily obtain the day of the week from dates? datas <- c("2010-06-28", "2011-05-25", "2010-09-28", "2011-12-05", "2010-09-14", "2010-01-01",…
-
6
votes1
answer80
viewsMax of a numeric field returning NA
I’m starting to learn R and I came across a situation I don’t understand. I downloaded the data from ENEM 2014 (CSV file) and read using: dados_enem <- read.csv(file="MICRODADOS_ENEM_2014.csv",…
-
6
votes1
answer279
views3D histogram using ggplot2
I have data of a two-dimensional distribution, for example, uniform. I wish to make a histogram with this data. I tried the package plot3D, but it wasn’t very nice. teste = matrix(runif(100), ncol =…
-
6
votes0
answers180
viewsPseudo forecasting (Rolling)
How to make pseudo predictions out of the sample, through rolling regressions and with mobile window containing 50 observations, to t = 51 to 100? One of the predictions should be made from an…
-
6
votes1
answer219
viewsStargazer changing position of dependent variable
Considering the quantile regressions. library(quantreg) > x=rnorm(100,12,2) > y=rnorm(100,0,4) a<-rq(y~x,tau = .10) b<-rq(y~x,tau = .15) c<-rq(y~x,tau = .20) d<-rq(y~x,tau = .25)…
-
6
votes1
answer370
viewsError as.POSIXlt.Character when importing MDB into R
Hi, I looked all over the internet for that answer and I didn’t find :) I am importing an MDB (Ms Access db) into R Studio (Windows 7 R v32b) using RODBC but when giving the sqlFetch command I am…
-
6
votes2
answers858
viewsWhat are the differences between require() and library()?
In R, what are the differences between require() and library(), if there? When should I include the require() and when should I include library()?…