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
answers620
viewsHow to smooth a curve and define ylim for a given function using ggplot2?
I got the following graph with the curve function: f1 <- function(x){x^4 - 6*(x^2)} curve(f1, xlim = c(-3, 3), ylim= c(-10, 5), ylab = expression(x^4 - 6*(x^2))) However, I would like to use the…
-
5
votes1
answer172
viewsRename a file with a vector value
I am using a loop to extract hundreds of data using unzip. However, I want to rename the files with the same name as the extracted file. I’m making the following code: zip_postos <-…
-
5
votes1
answer880
viewsData manipulation with in-line dates for column
I have a database a little difficult to work with: The code variable is 141 different. What I wanted to do was create a data.frame that had code as a variable (header) and so had a sequence of days…
-
5
votes4
answers1852
viewsProgrammatically generate and download links
There is a database of the National Water Agency that can be accessed by Hydroweb. To download is just access: Hydrological Data > Historical Series and include the desired rain station code.…
-
5
votes1
answer122
viewsComparison of two matrices with different sizes
I have two matrices with these dimensions and would like to remove the common lines between the two matrices and form another matrix without these elements. How R could do that? a = matrix(1:30,…
-
5
votes1
answer492
viewsOperation with three-dimensional arrays
Reformulating the question, I would like to implement the following equation: Where D is a matrix of order i x k x l, lambda is a matrix k x j and pk = {1,2,3,4,5,6}. For this I need some function…
-
5
votes2
answers1265
viewsDaily Time Series Decomposition
I have a time series of daily flow data. I am trying to decompose the ST to remove trends and seasonalities. But when I use the function decompose the seasonality chart appears a black blur. QHE.ts…
-
5
votes2
answers361
viewsHow to Create a Bubble Plot
Anyone with experience in formulating this graph? I am very doubtful, especially in the diameter of the circles and in the placement of the variable of the X-axis. I am a doctoral student at UFPE…
-
5
votes2
answers122
viewsHow can I get maximum and minimum values after applying LOESS
My data is brought from a database and I simply apply: ggplot (data = df_postgres, aes (x = date_time, y = duracao)) + geom_point() + stat_smooth(method = "loess") And I get the following smoothing:…
-
5
votes1
answer2787
viewsHow to read PDF data in R?
I have numerous PDF files containing water well reports from CPRM, like this: http://siagasweb.cprm.gov.br/layout/pdf/exportar_pdf.php?ponto=4300000556 Inside these files are information about the…
-
5
votes1
answer2745
viewsR how to generate a time series?
I would like to know how to generate a time series of a file that has two columns (date and value), but the date is in the following format yyyy-MM-dd. When I use the ts() command, it replaces the…
-
5
votes1
answer355
viewsIntegration between PHP and R
I am developing a project with php and decided to use R for statistical calculations. But I’m not sure how to accomplish this integration. If there is a "design pattern" for situations like this.…
-
5
votes2
answers2993
viewsEliminating Double Lines from a Data.Frame
I have a data.Frame with the following behaviour: values ind 1 10.82000 2011-01-03 2 11.75000 2011-01-03 3 10.82000 2011-01-03 4 11.75000 2011-01-03 5 10.82000 2011-01-03 6 11.75000 2011-01-03 7…
-
5
votes2
answers200
viewsHow do you store a chart as a variable and export it later?
Considering: x<-1:10 y<-10:1 plot(x,y) I would like to store the result of plot() in a variable, such as grafico<-plot(x,y) is it possible? And to export as I do?…
-
5
votes1
answer142
viewsWhat function in R to reorder a data.frame that contains missing data (NA)?
I got the following data.frame: Linha Data Total Med.2 DP.2 Med.3 DP.3 Med.4 DP.4 1 2009 1.4749 NA NA NA NA NA NA 2 2010 2.9945 2.2347 1.0746 NA NA NA NA 3 2011 2.9945 2.9945 0.0000 2.4880 0.8774 NA…
-
5
votes1
answer876
viewsHow to build an executable/installer from a routine written in R?
I have several routines written in R, simple tools, which I would like to share with my colleagues. However, some of them do not have any knowledge in programming. So I want to facilitate the use of…
-
5
votes1
answer4952
viewsHow to generate random values for a known distribution?
I am aware that, for example runif(1000,0,3) generates 1000 random values for a uniform distribution for x between 0 and 3. But how to do this for any probability density function? Every clue is…
-
5
votes1
answer137
viewsRemove zero column from an array
I have a three-dimensional array and within that array there is another array of zeros and I want to remove it from the larger array. For example, set.seed(1) a = rnorm(60) b = array(a, dim = c(10,…
rasked 8 years, 10 months ago Wagner Jorge 1,377 -
5
votes1
answer241
viewsProgrammatically generate links and download content
I would like to know how I would collect data from a website. The site is http://www.ons.org.br/historico/energia_natural_afluente.aspx . There I have to download all the operational historical data…
-
5
votes4
answers2494
viewsHow to join observations of tables that have a different set of variables in R?
In the case below id corresponds to observations contained in two different data frames, in df1 the observations have the variable x and in df2 the observations have x and z In these cases how to…
-
5
votes1
answer436
viewsHow do I make tables smaller from a data.frame in R?
I have a table in data frame, with 100 animals, but with 500 observations of various characteristics. as I do to have subtabels, with only the animals and the characteristic x, where q should show…
-
5
votes1
answer582
viewsHow to combine two vectors and get all the results of a given account with them
I’m trying to make a calculation, and I need your help. First I make a sequence with normal distribution with 420 numbers, then I make a sequence of numbers I call mci with 42 numbers, then the next…
-
5
votes2
answers878
viewsloop in correlation matrix in R
I have tried to learn about loops and functions in R. So I disposed to the following situation: I have a matching correlation matrix: dados<-matrix(rnorm(100),5,5)…
rasked 8 years, 8 months ago Ricardo Adelino 73 -
5
votes1
answer2373
viewsHow can I get the current date and time in #R?
I am creating a routine process report, a simplified "logfile", and would like to store the date the time of the error moment in a variable. What function results in the date and time of the moment…
-
5
votes2
answers502
viewsTime Series autocorrelation
Consider the stochastic process AR (1). Generate a sequence of 500 random variables and assume c = 3 and Phi = {0.5, 0.95, 1}. Make autocorrelations from 1st to 3rd order (CR). How to generate these…
-
5
votes2
answers1742
viewsProcessing time of functions
How I check the processing time of the subfunctions of a function in order to optimize it? I read about it in R help and in:…
-
5
votes1
answer105
viewsBuild Data Frame with "get" Function
This is my date.: data<-read.csv2("NewEXEMPL.csv",header=TRUE,sep=";") head(data,5) DATE P.A i.A S.A w.A b.A P.B i.B S.B w.B b.B P.C i.C S.C w.C b.C 1 jun/79 16.86 59.67768 12.3125 0.4291845…
-
5
votes1
answer365
viewsExtract elements from a List
I have this list: a <- list() a[[1]] <- matrix(c(1,2),nrow = 2) How do I select element 2 ?
-
5
votes1
answer531
viewsImpulse-Response function in R
I have a question about the output of the function irf package vars. What is the difference with the output as to the arguments _cumulative = TRUE/FALSE_ and _ortho = TRUE/ FALSE_? Another thing,…
rasked 8 years, 4 months ago Cleyton Farias 51 -
5
votes1
answer70
viewsDate - 4 digit Character conversion
I’m having trouble using as. Date to convert a column with dates (year with only two characters) into date. O as. Date autocompletes the year wrong, producing results like 2066( instead of 1966)…
-
5
votes1
answer111
viewsData presentation in ggplot2
Hi, I’m having trouble at ggplot2 on a histogram. The code: ggplot(data.combined[1:891,], aes(x = Age, fill=Survived)) + facet_wrap(~Sex + Pclass) + geom_histogram(binwidth = 10) + xlab ("Age") +…
-
5
votes1
answer473
viewsHow to make the webscrapping of a site that has post method?
I’m having trouble doing the webscrapping for sites using the method post, for example, I need to extract all news related to political parties from the website: http://www.diariodemarilia.com.br.…
-
5
votes1
answer73
viewsTimeout when using httr:POST()
Expensive, I’m trying to hold a conference of records at CREA-RS website, but every time this giving the following error: Error in curl::curl_fetch_memory(url, handle = handle) : Timeout was reached…
-
5
votes2
answers183
viewsTrying to generate a graph of a time series
That’s what I did.. #Lê a base de dados ano1<-read.csv("os dados abaixo...",header = TRUE ,sep=";", row.names=1) #Cria a série temporal ano<-ts(ano1[,1],start=c(2009,1),…
-
5
votes1
answer115
viewsOperation with very large size lists
I have a code that calculates the area of the intersection between two polygons and for that I use lists to store the coordinates of the vertices of the polygons, however there are many polygons and…
-
5
votes1
answer195
views -
5
votes1
answer6021
viewsHow to concatenate two strings?
Supposing I have two strings, Olá and mundo!, as I grant them using R?
-
5
votes1
answer135
viewsWeb Scraping: How to change the value of a drop down button on a site using R?
I want to create a script in R to read an HTML table. Do this from a static page with the package rvest is easy, the problem is that I have to change the value of two page buttons. This is the site…
-
5
votes1
answer302
viewshow to increase the limit of ifelse in R?
I need to calculate the years of study from the Pnad questionnaire. I did a programming similar to this one below, but I have many ifelse within the other (121 to be exact), because I have a larger…
-
5
votes1
answer79
viewsbRasilLegis [ command "get DetailsDeputed"]
I need to collect the data of the deputies who were present in committees, positions, etc. However, I can only do this with one deputy at a time. It’s possible I can choose them all at once?…
-
5
votes1
answer2161
viewsConcatenate two columns of an array into a string of characters
Suppose I have the following vectors: n <- c(1:5) c <- c("A","B","C","D","E") I build the following matrix with them: m <- matrix(c(n,c), ncol = 2) What is the best way to obtain such a…
-
5
votes2
answers172
viewsHandle values of a data.frame
On the link https://1drv.ms/u/s! Alyjgc4yfdharhtsiuubju12gzho it is possible to find a dataset in csv on solar irradiation in Brazil. The column the_geom_4326 represents the longitudes and latitudes…
-
5
votes2
answers800
viewsHow to convert numbers into categories in R
In my database, I have a Variable TP_CorRaca with the values 0, 1, 2, 3, 4, 5. Each number corresponds to a color. Example: 0 - White 1 - black 2 - brown ... I want to make that match to use the…
rasked 7 years, 8 months ago André Oliveira 376 -
5
votes2
answers726
viewsHow to rename the database (Rdata) in R?
I have the following situation: I need to merge two banks. The name of both the database files are: banco2.RData and banco2_2.rdata However, when I open the banks in the R they have the same name:…
-
5
votes2
answers5899
viewsfile read . XLSX in R
What is the problem and/or difference between reading a file in .txt and .xlsx in the R? Reading in .xlsx can have more problems than in .txt during an analysis ? A friend asked me to do everything…
rasked 7 years, 8 months ago Herlon Nadolny 63 -
5
votes1
answer1261
viewscolor gradient R
How do I change the color of the graph gradiently with the years variable, starting from white to intense red. colourCount = length(unique(tabela.estacao$ano)) getPalette =…
-
5
votes2
answers1839
viewsColumn chart stacked in R
I have a database where variables assume integer values from 1 to 5. Follow an example base with variables X1, X2 and X3: base<- rbind( c(5,3,3),c(4,3,2),c(4,5,4),c(1,5,1),c(1,2,1),c(3,4,2),…
rasked 7 years, 8 months ago Henrique Pizarro 659 -
5
votes3
answers202
viewsHow to assign NA as value?
I have the following line of code: enem$TP_COR_RACA <- factor(enem$TP_COR_RACA, levels = 0:5, labels = c("Nao", "Branca", "Preta", "Parda", "Amarela", "Indígena")) I want to replace the value…
rasked 7 years, 7 months ago André Oliveira 376 -
5
votes1
answer1228
viewsCalculating Integral using R
I need to calculate this simple integral below: It is the quantile function of the standard normal, where before hand we know that, q_0.5(z) = 0, for example. That is, for each theta (percentile) it…
-
5
votes1
answer114
viewsBuilding a function by defining x and y using R
I have this matrix: matrix=structure(c(0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2, 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27,…