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
votes1
answer428
viewsWeighted linear regression using the inverse of variance as the weighting factor
I have the following data set that establishes a relationship between two variables "X" and "Y": df <- data.frame(X=c(25,25,25,25,25,25,50,50,50,50,50,50,…
-
3
votes1
answer48
viewsR code_with() function
What does this line of code mean? with(epilepsy,by(seizures/timeadj,list(treat,expind),mean)) the data is from the package faraway.
rasked 7 years, 6 months ago Maria Lopes 115 -
3
votes1
answer463
viewshnp function - R hnp package
My model was created with the function glmer, pacete lme4. It is a generalized linear mixed model with binomial response. form=status~(A1+A2+ B1 + ... + B10 + (1 | escola)) Mod1 <- glmer(form,…
-
3
votes1
answer163
viewsIn a matrix Z of elements (i,j) how to assign the value 1 when i=j? (software R)
Under the following condition: ifelse(??, 1, Z/(1+1)) What to put in place of "??" so that R understands that when i=j in the matrix Z, I want to assign the value 1?…
-
3
votes2
answers726
viewsCreate sequential counter
I need to create an occurrences count column of a value present in another column. For example, counting in column "y" of elements present in column "x": x y 1 A 1 2 B 1 3 A 2 4 C 1 5 B 2 6 A 3 I’ll…
-
3
votes1
answer695
viewsHow to count different lines in R
I have the following table: Material Fornecedor 1 A 1 B 1 A 1 C 1 C 2 B 2 D 2 E 3 A 3 B 3 C 3 F 3 G 3 A 4 A I need to create a new column of 1 and 0, where 0 will indicate that that supplier has…
-
3
votes3
answers1016
viewsSplit a data frame and save to different directories
I have a data frame composed of 100 lines and two columns (name and quantity). The quantity column is an integer number ranging from 1 to 4. How can I split my original data frame into four data…
-
3
votes1
answer1008
viewsHistogram R. Changing the values of the axes!
I have a variable with the following value: > pontos c d b a 0.6666667 1.0000000 0.3333333 0.6666667 hist(dots, main="dots ", xlab="p", ylab= "f") the result is: My values of the X axis will…
-
3
votes1
answer179
viewsWhat is the "listw" argument in the multispati (multivariate Spatial analysis) - R software?
It involves spatial dependency, but I’m not sure how.
-
3
votes1
answer511
viewsCalculation with Matrices in R
What functions should I use to make the following calculations with matrices in R: - Find the transposed matrix; - Find the inverse matrix; - Find the identity matrix; - Finding the determinant of a…
rasked 7 years, 4 months ago Bruno Rigueti 305 -
3
votes1
answer127
viewsReturn of the gradient function when using Optim and colSums functions
I can’t understand why when using the function gradlik as a function argument Optim I get the following error: Error in optim(beta, loglik, gradlik, method = "BFGS", hessian = T, control =…
-
3
votes2
answers11355
viewsSelect column of a data.frame --- Database Division in R
I imported a table as a database to handle in R. However, I need to do some calculations with just a few columns of this table. How do I select only these columns for calculations?
rasked 7 years, 4 months ago Bruno Rigueti 305 -
3
votes3
answers243
viewsHow to filter data according to part of the characters of a variable?
How can I, for example, list only the observations it contains in the variable Name, the word Silva? Nome Nota João Silva 9 Pedro Souza 8 Ana Silva 6 Isabela Cabral 10 Paulo Santos 5 I would like…
rasked 7 years, 4 months ago Filipe Wanderly 33 -
3
votes1
answer519
viewsRead file with non ascii format [à="<U+00E0>"]
I’m reading a file on R called roubobs.rds. is a proprietary R format and I could not open in excel. I can import the data into a variable but, within the records, the texts are not ascii (Unicode?…
-
3
votes1
answer83
viewsChange output in Shiny only when I change value in numericInput()
I have this table in my Shiny app. | a | 2 | | b | 3 | | c | 5 | Has a box to choose a line (from 1 to 3), and from this it prints the value for that line. There is also another box so I can change…
-
3
votes1
answer120
viewsHow to parallelize the.call function
I need to do a multiple montage rasters for a single raster. Both the function raster::merge how much raster::mosaic work well in this situation, but I need to make a do.call to call the function to…
rasked 7 years, 10 months ago Vivian Ribeiro 39 -
3
votes1
answer41
viewscreate sequence that increases and decreases monotonically
I have the following vector: > a [1] 64.42 66.99 100.39 97.96 97.96 96.26 94.22 92.35 86.05 84.01 I wish that I could generate another vector that grows and decreases monotonically, whatever the…
rasked 7 years, 3 months ago Artur_Indio 1,093 -
3
votes1
answer423
viewsHow to change map scale in ggplot2?
I’m making a map with ggplot and ggmap. However, the axis scales are in decimal degrees, but I need them in degrees, minutes and seconds. Thank you for your cooperation!
-
3
votes2
answers1908
viewsHow to convert Hour:minutes:seconds to decimal number in R
I am trying to convert a column in the date.frame that is in the format of hour:minutes: second to decimal number Example: 2:20:00 to 2,33 How can I do it in R?
rasked 7 years, 3 months ago Luciano Hauschild 431 -
3
votes1
answer1515
viewsWith merging several txt files into one
I have 60 txt files all with the same number of columns. The files have no header (column name). How can I join them all in one file just below each other in R.
rasked 7 years, 3 months ago Luciano Hauschild 431 -
3
votes2
answers1053
viewsread.table, data.frame
I try to perform this section below and it occurs: rain.df<-read.table("C:\\Users\\Marcia\\Desktop\\Sript R\\daily.dat", header=TRUE) Error in scan(file = file, what = what, Sep = Sep, quote =…
rasked 7 years, 3 months ago Robson Antas 39 -
3
votes0
answers461
viewsMachine Learning using R and excel
Hello I have some data that I tabulate in excel monthly, which is very repetitive. I wonder if there is any way to use machine learning in R to teach an algorithm, based on the data I already have,…
-
3
votes2
answers94
viewsTransform duplicate values to 0 by keeping an element in the conditional R
Suppose there is a database in which: x y z a 2015 122.4 a 2015 122.4 b 2016 200.5 a 2014 300.6 c 2016 80.1 What I was wondering is with making a programming in R that transforms the repeated values…
-
3
votes1
answer375
viewsHow to define initial kicks for nls function for potential regression model?
I would like to know how to define the initial "kicks" to use the power nonlinear regression model. I am working with estimation of data, testing various regression models, even if there is no…
rasked 7 years, 9 months ago Jean Karlos 646 -
3
votes1
answer64
viewsperform . Globalenv function in parallel processing
I need to execute a function that is in . Globalenv in a parallel processing using the multidplyr package. Using a simple example without parallel processing, it works as expected: library(dplyr)…
-
3
votes2
answers422
viewsCode for viewing Boxplot in ggplot2
in viewing the boxplot created with the script below, it does not seem to me that the graphics g2, g3 and g4 are the same that appear in the image g1, but I couldn’t find anything wrong in the code!…
-
3
votes2
answers538
viewsHow to select data in R?
I have a database with 1441 lines. I need to group them into groups of 30, and extract averages from each of these subgroups. Is there a command that allows me to do all this automatically? "every…
-
3
votes1
answer1345
viewsHow to keep only Dataframe-specific lines?
I have a code that enters a site, fills in a form and pulls a table, however, I want to delete some rows from this table that I don’t need. Let’s go to the code: #library's require(RCurl)…
-
3
votes1
answer3210
viewsDisplay the position of a given value on a vector in R
I started studies in R a short time ago and I have studied this language a lot. However, I am having difficulties in how to get the position of a vector, that is, the order in which a certain value…
-
3
votes1
answer178
viewsPOST function of the httr package returns NA
I’m trying to make a script on R to make a POST on the site: http://tabnet.datasus.gov.br/cgi/tabcgi.exe?sinannet/cnv/violebr.def, but I am not succeeding. The goal is to extract the generated data…
-
3
votes2
answers830
viewsIndex searches on an R vector
In Rstudio how to choose elements of a vector that are in even or odd positions?
-
3
votes2
answers126
viewsGenerate repeated values in R
In the frame date below I want those on days that have no gain information that the gain is repeated based always on the last collected information. For example from day 2 to day 15 the gain will be…
rasked 7 years ago Luciano Hauschild 431 -
3
votes2
answers85
viewsDecrease default error in Fitting (Std Error) R
I was trying to adjust a theoretical function to a point distribution through the function nls2. However, the errors of the adjustment are very large, that is, if a parameter must be between 2 and…
rasked 7 years, 6 months ago david clarck 333 -
3
votes2
answers490
viewsModify t test for linear regression parameters in R
I would like to know how I can change the t test in relation to the parameters of a linear regression in R. I would like to test whether B0 = 0 and whether B1 = 1. Generally, the output of a…
-
3
votes2
answers530
viewsFilter Different Texts in R
Good afternoon, I have the following data: NOME <- c("LEITO 1001", "LEITO 1002", "LEITO 1003", "LEITO 50", "LEITO 60") VALOR <- c(10, 20, 30, 40, 50) dados <- data.frame(NOME, VALOR) I need…
-
3
votes1
answer175
viewsInvert factors in only 1 bar in ggplot2
Does anyone have any idea how the order of the factors in only 1 bar in ggplot2? Reordering the data no longer works :( In case I would like to reverse the first bar, so that the green was up and…
-
3
votes1
answer1331
viewsHow to join two data.frames in R with different variables and out of order?
I have two date frames.: frame1 <- data.frame(dia=c("02/01/2017","03/01/2017","04/01/2017","05/01/2017"), y=c(2,2,1,2),w=c(4,4,2,2),z=c(25,16,24,30), k=c("sim","nao","sim","nao")) frame2 <-…
-
3
votes1
answer49
viewsstring transformation in R
I wonder if I can turn an observation of a variable, which has a string shape, into uppercase letters. for example: #como esta: x=c("Casa branca","Barco Azul","casa preta") > x [1] "Casa branca"…
-
3
votes1
answer4316
viewsError: non-numerical argument for binary operator
I’m working on the following code: temperatura<-function(t){6/pi*atan(40*t-740)+7}#temperatura em função do tempo…
-
3
votes2
answers85
viewsMultiple Gather with 4 resulting "joint" columns
Hi, I have the following situation: I have a data frame with several columns, a group of them I want to transform into key value. So far so good, but there are 2 groups and they can’t just sort of…
rasked 7 years, 4 months ago Geovani Ferreira 129 -
3
votes1
answer560
viewsHow to smooth this graph in R/Rstudio?
If I plot the chart normally pontos.x = c(7.522936, 12.228712, 17.316037, 22.148996, 27.236321, 32.196464, 37.283789, 42.116748, 47.076890, 52.164215, 57.378723, 62.211682, 67.426190) pontos.y =…
-
3
votes1
answer98
viewsR - How to sample pairs from an array without repeating values?
I’m trying to create 100 pairs from a 200 value vector. I built a vector following a normal distribution as follows: vetor=rnorm(200,mean=30,sd=6) And now I want to extract 100 pairs of these…
-
3
votes1
answer139
viewsDegrees of freedom Anova R
I’m trying to run a basic one-way ANOVA on R. library(drc) data=S.alba aov(DryMatter~Dose,data=S.alba) However, there are 7 treatments in this data. Therefore, DF (Gree of Freedom) or Degrees of…
-
3
votes1
answer152
viewsHow to separate a time series basis into periods
I have a time series basis. On the basis has information of consumption of pig feed (follows below with information of only one day and one animal). There is a column with identification of the…
-
3
votes1
answer2384
viewsAdd two or more covariables to the R
I have a database with several ID (rows) and in the columns the covariables. These covariables are repeated in other columns with different information about the same ID. How to join these…
-
3
votes1
answer761
viewsHow to transpose rows into columns (and vice versa) and save to a new database?
My database has 10 cases and 6 variables. I want to transpose the cases in column and save this transposition in a database.
-
3
votes1
answer530
viewsR - How to calculate the price change from one period to another?
Hello, I would like to know how to calculate the price variation from one period to another. Example: Year | Price 2007 | 25 2008 | 30 2009 | 7 2010 | 15 ... |...|... The new column would be: Year |…
-
3
votes2
answers71
viewsCalculate the product of an operation between two dataframes conditionally
Suppose I have these two dataframes: set.seed(123) df1<-data.frame(rep=rep(1:4,each=360),parc=rep(1:40,each=36),trat=rep(sample(1:10),each=36),tree=rep(1:36,40),med=1,dap_prev=rnorm(1440, mean =…
rasked 7 years, 1 month ago Aníbal Deboni Neto 31 -
3
votes1
answer337
viewsRandom choice of lines in an array in R
I have a problem that produces a numerical matrix mxn being m the number of observations (row) and n the number of variables (column). I need to randomly choose p lines (p < m), without…
-
3
votes1
answer2369
viewsStacked Bar Graph - Labels and Sort - GGPLOT
I am building a graph indicating the population of the Brazilian states, organized by regions, according to the code below: State <- c("Rondônia", "Acre", "Amazonas", "Roraima", "Pará", "Amapá",…