Questions tagged as 'r'

1
answer

How to optimize the removal of rows in an array?

I have an array of dimensions: > dim(filtro1) [1] 2806519 31 I need to remove rows from this array that meet a condition. So far so good. However, the computationally looping for this has been very expensive (time consuming - 8 to 1...
asked by 22.12.2018 / 12:52
1
answer

Recursion in R error

I have the following recursive function: tamanho <- function(v){ if (is.null(v)){ return(0) } i <- tamanho(v[-1])+1 return(i) } I'm using RStudio, and when I call the function with this example: tamanho(c(1,2,3,5)) gi...
asked by 21.10.2018 / 03:03
1
answer

What is the difference between numeric and integer vectors?

In R, identical vectors (containing the same numbers) can assume the numeric and integer classes. For example: x<-(1:5) class(x) [1] "integer" x<-c(1,2,3,4,5) class(x) [1] "numeric" Why does this occur? Which vector...
asked by 19.10.2018 / 03:30
1
answer

Argument of a function is another function

I would like to know how to put another function as an argument for a function. For example, let's say that I want to solve an integral by a given numerical integral approximation method. And I want to create a function that does this, in whi...
asked by 06.12.2016 / 12:22
1
answer

Change the order of the facet_wrap in ggplot2

See the code below, which generates the following graph: library(lme4) library(ggplot2) ggplot(sleepstudy, aes(x=Days, y=Reaction)) + geom_point() + geom_smooth(method = "lm", se=FALSE, color="black") + facet_wrap(~ Subject, nrow=3)...
asked by 15.09.2016 / 19:52
1
answer

Export R data to Excel formatted

Assume 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", "Total"), row.names = c(NA, -4L), class =...
asked by 23.04.2014 / 02:08
2
answers

How to do an optimization with restriction of inequality?

Suppose I want to minimize the following function: -(5-(x1-2)^2-2*(x2-1)^2) s.a. x1+4*x2 < 3 For unrestricted optimization problems I can use the following code. fr <- function(x){ x1 <- x[1] x2 <- x[2] -(5-(x1-2)^2-2*(x...
asked by 05.04.2014 / 00:03
2
answers

How to decode many columns from a data frame of R

I have a data frame with more than 300 columns that are categorical but are encoded as numeric. Each of these columns has its own "type", that is, it has its own coding table. My problem is to create a new data frame with decoded variables. I...
asked by 15.04.2015 / 19:07
1
answer

How to combine two vectors and get all results from a given account with them

I'm trying to do a calculation and I need your help. First I make a normal distribution sequence with 420 numbers, then I make a sequence of numbers that I call mci with 42 numbers, then the next calculation has a if condition....
asked by 20.02.2016 / 03:20
1
answer

Stargazer changing the position of the 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) As I just have a constant and an explanat...
asked by 16.05.2016 / 22:40