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
votes1
answer45
viewsRandomizing two sets of numbers, not repeating the values within each group (R)
Whereas I have these individuals on file: ID 1 1 1 3 3 3 7 7 7 And I need to assign two sets of numbers to ID randomly (set1 - 1,2,3; set2 - 5,15,25). To do this my attempt was: df %>%…
-
5
votes2
answers70
viewsError plotting with ggplot
library(tidyverse) library(lubridate) Suppose a dataset containing the year followed by the number of books published by an author: df<-tibble( ano = c(2007, 2008, 2017, 2018), n = c(1, 2, 2, 1)…
-
5
votes1
answer35
viewsHow to check if a value is contained in another list
I need to check if the value of a column is contained in a list and, if it is, copy its value to a third column. Let’s take the example: df <- data.frame(Nome = c("Maria", "Pedro",…
-
5
votes3
answers102
viewsHow to do linear interpolation on R?
I have a date.frame with 3 columns: YEAR, COHORT and Income. I would like to make a linear interpolation between the values of 1960 and 1980 to define the values of 1970. To the COHORT = 5, would…
rasked 3 years, 4 months ago Alexandre Sanches 1,223 -
5
votes1
answer110
viewsReorder levels of a categorical variable within panels according to the group to which they belong
When using the command fct_reorder(class, hwy, .fun = median) below, I asked for the variable levels class were reordered according to median variable hwy: library(tidyverse) ggplot(mpg, aes(x =…
-
5
votes1
answer110
viewsInsert image with kableExtra function::spec_image( )
library(tidyverse) library(kableExtra) Suppose the following dataset: games <- tibble(logo = "", nome = c("Joao", "Pedro", "Geovanna"), medalha = c("Gold", "Silver","Bronze")) I want to add…
-
4
votes1
answer7167
viewsHow to count the cumulative number of occurrences of an element in a vector?
Suppose I have a vector in R: x <- c("a", "a", "b", "a", "b", "c") I need to determine for each position i of the vector, how many times the element x[i] appeared until then. The result for the…
rasked 10 years, 11 months ago rodrigorgs 6,635 -
4
votes3
answers180
viewsHow to include a variable high to n in regression
Suppose I have the following data x<-rnorm(100,1,10000) y<-rnorm(100,1,10000)+2*x+x^2 If I use the lm function as follows: model1<-lm(y~x+x^2) The R does not understand that it is to place…
-
4
votes3
answers6503
viewsHow to avoid encoding problems when picking up data with Twitter?
I’m taking Twitter data with the package twitteR for r but the tweets are coming with encoding. Someone knows how to get around this problem? library(twitteR) library(stringr) library(ROAuth)…
-
4
votes2
answers6494
viewsHow to create inverse matrix in R
To get the inverse of an array, we can use different R commands solve(), ginv(), etc, however, when trying to use these commands, an error occurs where we think the problem should be because there…
-
4
votes1
answer4059
viewsHow to run the current line in Sublime Text 2? Or, IDE that allows running the current line in Python
In the rstudio (IDE to r) it is possible to run the current line instead of the entire file using ctrl (or cmd) + enter. This is very useful for when you want to test just one piece of code separate…
-
4
votes1
answer941
viewsHow to create invertible random matrices in R
One of the ways to find the estimator using the method of least ordinary squares is by generating random matrices, given by the formula: B = (X’ X)^-1 X’Y Where Y = a+bx+cw+u, being x and w random…
-
4
votes2
answers97
viewsSubtracting matrices with different arguments
We can subtract two matrices (or two vectors) that were written with different commands? Example: x<-array(1:4,c(4,1,1)) y<-cbind(c(1:4)) x-y "Error> non-conformable objects" This means…
-
4
votes1
answer2475
viewsHow to transform a list into a vector in R?
How to transform a list into a vector in R? The list is a set of words and numbers and I need to add the numbers present in the list. mylist <- list ("2 tomates", "5 tomates", "9 tomates") If I…
-
4
votes1
answer602
viewsMinimum value of a row excluding zero (R)
TIMP3 TOTS3 UGPA3 USIM5 VALE3 VALE5 VIVT4 VLID3 WEGE3 1 0.7941716 0 0.00915221 0.2751215 0.3803796 0.5162442 1.505921 0 0.5559166 2 0.7710909 0 0.09351134 0.3925726 0.3687917 0.5158750 1.469548 0…
-
4
votes1
answer147
viewsHow to import data from clibboard to a data-frame in R
One of the advantages of using spreadsheet is that we can import data from the Clipboard. Is there any way to do it in R?
rasked 10 years, 2 months ago Guilherme Duarte 918 -
4
votes1
answer287
viewsloop objects
I need to make several regatta . for example: 2012ocup10 <- aggregate(PNAD2012[c("peso_pes")], by=PNAD2012["klems"], FUN=sum,na.rm=T) but I need to perform the same procedure to…
rasked 10 years, 2 months ago Ennio Ferreira 43 -
4
votes2
answers2111
viewsI can’t install Ibgepesq in R to read the Pnads
I just downloaded the 2013 PNAD of IBGE -- and I tried to open it with the package for R that IBGE itself elaborated, the Ibgepesq. It is available as . zip archive at this address:…
-
4
votes2
answers1789
viewsA: What objects does the Names() attribute apply to?
I’m a little confused by the role of attribute names() on different objects. In addition to normal use, in data.frames, I see in the examples of help(names) which can also be used for vectors (both…
rasked 10 years, 1 month ago LucasMation 411 -
4
votes1
answer330
viewsClassify a text array using regular expressions using R
Let’s say I have the following array of texts (character): d <- data.frame(id=1:3, txt=c('Um gato e um cachorro', 'Cachorros jogam bola usando alpargatas', 'gatinhos cospem bolas de pêlos'),…
-
4
votes2
answers823
viewsDplyr and gsub: how to replace parts of one column with another
I have the following data-frame: xis <- data.frame(x1=c("**alo.123", "**alo.132", "**alo.199"), x2=c("sp", "mg", "rj"), x3=c(NA)) I would like to create a new column, using gsub as follows: x3[1]…
-
4
votes1
answer255
viewsDifferences between Rcurl, httr (R) and requests (python) when making a POST
I was wanting to access a page that gets you by clicking "Displays all the above documents" at that link. The company I took is just an example, I have no interest in it. I tried to resolve this…
-
4
votes3
answers19175
viewsHow to calculate the average of a column in R?
I have an Excel file in format .csv(comma separated values) and I want to read what is in a column, add and calculate its average. How to open the file I already know, but I don’t know how to add…
rasked 9 years, 11 months ago Van Ribeiro 1,482 -
4
votes1
answer736
viewsNeural networks with the package "AMORE" - R
Dear colleagues, I am trying to use the AMORE package of R to run a Neural Network with new activation functions, but I could not understand very well the manual and consequently could not implement…
-
4
votes2
answers106
viewsData window moving in time (t)
I want to make a recursive prediction. I need each month (t) to move the data window of the last month forward in a period (monthly period, that is, t+1).…
-
4
votes2
answers93
viewsDoes R have a similar command to SAS IN?
R has some command similar to SAS IN? Follow an example in SAS code: variable1 IN (4,5,6,7) THEN variable2 = 1; That is, if the variable1 assumes the values from 4 to 7, the variable2 is assigned…
-
4
votes1
answer332
viewsRepeating structure in R
I’m not getting a logic to do the following problem in repetition structure: I have an A vector with 1 element and another B with 30 elements. I wanted to subtract vector A from each element of B so…
-
4
votes1
answer2623
viewsMerge csv files into one
I have several csv data files that have a common column named "Data". If I read two files from this directory the reading is done in the correct way: > P1<-read.csv("02650019.csv", header =…
-
4
votes1
answer1187
viewsHow to delete axis title in graphics in R?
I am doing multiple regressions for the same variable X and filling together using the command par(mfrow) in the R. But I want to put only one title on the X axis at the end of all my charts. I…
-
4
votes2
answers1551
viewsHow to group data by an id in R
I have the following database: id x 1 2 1 3 2 3 3 3 3 3 3 3 I wanted to create a new database without repeating the field value id, to solve this I can average the field values x that belongs to the…
-
4
votes1
answer321
viewsSpatial analysis in R: how to implement a polygon with splancs?
I’m trying to calculate the intensity of a point pattern with "Smooth kernel" (sorry, I don’t know how to translate this). Before executing Smooth kernel code, you need to specify a histogram…
-
4
votes1
answer1219
viewsFilter and save to csv
I would like to perform a filter on R. I have a database with 5 variables and more than 5000 lines. One of my variables is "room", in which I have 29 room (ex:Sala1,sala2...). I would like to…
-
4
votes2
answers108
viewsUpdating Mysql table using sqlSave in R
I’m new to R and I’m trying to add new tables to the database,: Error in sqlSave(connection, dado, tablename = "teste", rownames = FALSE, : unable to append to table ‘teste’ Where: dado =…
-
4
votes1
answer864
viewsImport Latex to R Markdown
Hello! Probably this question has already been addressed here but I did not find... I use R Markdonw to generate manuals on certain R commands, but I made a diagram in Latex and wanted to know if…
-
4
votes2
answers2923
viewsComparing contents of a Column
I’m a beginner in R and needed help comparing column content. First I sorted my table according to a specific column. For this I used the following function: x = fread ("x.txt",sep=";") x_ordenado =…
-
4
votes2
answers5264
viewsHow to import data (.csv) to R while maintaining the original format
I am trying to import data from Excel (already in .csv format) to R; the values contained in the files to be imported are in the following formats, for example 8509.80... To import, I am using the…
-
4
votes1
answer1049
viewsHow to transform data imported from Excel (.csv) into time series
I imported an Excel database to R and I need to turn it into time series to be able to analyze it. However, when I am going to make the transformation to time series R changes the original values to…
-
4
votes1
answer113
viewsUse regression residues to calculate another regression (within the function) in R
I’m using a function to calculate regressions. I need the residues of a specific relation to relate to another variable. However I need the waste to be calculated according to Facet grid. Thus, for…
-
4
votes3
answers611
viewsHow to build time series with frequencies different from the original?
I have a dataframe with daily precipitation data, with dates 01/01/1900 until 31/12/2010, example: # Data Est_1 Est_2 Est_3 # 17/12/2010 NA 0 0 # 18/12/2010 NA 0 0 # 19/12/2010 NA 1.7 0 # 20/12/2010…
-
4
votes2
answers81
viewsObtain the Summary of the results from the use of the LOESS
I wonder how I can get the points that are generated by my curve. I’m having trouble getting the results of my last code statement. In addition, I got the upper and lower points of the curve, but I…
-
4
votes1
answer193
viewsUpdate XLS spreadsheet without overwriting data using R
I need to add new information to the xls spreadsheet, but this already has information that was previously inserted. I need that data to be on the same sheet. There is the possibility to update a…
-
4
votes0
answers425
viewsI cannot reproduce the government data of PNAD 2013 from microdata
The government announced last year the result of PNAD 2013, it appears that there 85.3% of the houses had piped water. I downloaded the microdata from PNAD and with R tried to reproduce the analysis…
-
4
votes1
answer757
viewsR does not create graph correctly
I am using R to generate table charts, with two fields (company name and sales quantity), when using barplot, it is not putting the right values in the fields. For example, if sales were 500,000 it…
-
4
votes2
answers175
viewsApply function in data groups
I need to separate the data into groups and perform the calculations in two or three groups/dimensions. I found the tapply function, it solves the problem. With it I get what I need by using the…
-
4
votes2
answers292
viewsggplot data.frame
I have a data.frame (df): Mês SpreadMensal 1 jan2006 -3.04045769 2 fev2006 -3.39026284 3 mar2006 -2.52839603 4 abr2006 -1.52792341 5 mai2006 -0.08979180 6 jun2006 1.02865488 7 jul2006 0.54515613 8…
-
4
votes2
answers1624
viewsReversing Order column data.frame
I have this data frame: > head(df1) data spread 1 2006-01-01 -3.0404577 2 2006-02-01 -3.3902628 3 2006-03-01 -2.5283960 4 2006-04-01 -1.5279234 5 2006-05-01 -0.0897918 6 2006-06-01 1.0286549 >…
-
4
votes1
answer244
viewsData Frame and Linear Regression
With this data frame I need to run some regressions. I want to make regressions with terms raised to 3 and lagged. I looked in the lm package and could not implement. I want for example to rotate…
-
4
votes2
answers632
viewsHow to group microdata of census persons by residence?
I am trying to answer the following question: How many couples with children under 18 both parents work outside? Given a table censo of the 2010 census (as the one from Acre), first thing I did was…
-
4
votes1
answer672
viewsR-Studio - Package installation error
I try to install the package from the .zip, but the following message appears: R Tools for Biologists (Rt4bio) Funtions: rdiagnostic: Make a Diagnostic residuals Plot. plotbar: Use barplot2 from…
-
4
votes2
answers417
viewsUse of the GREP Function
Hello, I have a . csv file with the zip code in the middle of the address, in square brackets. In some cases there is no zip code, but there is always the set[], possibly empty, for example: RUA…