Posts by Daniel Falbel • 12,504 points
268 posts
-
1
votes1
answer99
viewsA: Installation mgarch Package on R
Assuming that the devtools has been installed correctly, you need to use the command: library(devtools) install_github("vst/mgarch") and not install_github("mgarch"). mgarch is the name of the…
-
5
votes1
answer2623
viewsA: Merge csv files into one
I don’t have your files here to test, but I would do something like this: setwd("C://...") # caminho par ao seu diretório arquivos <- list.files(path = "C://..", pattern = "*.csv") # caminho para…
ranswered Daniel Falbel 12,504 -
4
votes1
answer995
viewsA: In R, create a function to change some levels of a variable
I did the following function: juntar <- function(dat, variavel, levls, novosLevls){ # pega o nome da variável variavel <- deparse(substitute(variavel)) # cria data frame auxiliar para dar…
ranswered Daniel Falbel 12,504 -
10
votes2
answers6648
viewsA: How to change the language of R?
Go to the folder where R was installed which should be so: Enter the folder etc and edit the file RConsole: Change the line that starts with language = and put language = en.…
-
5
votes1
answer259
viewsQ: Select first lines depending on group efficiently
Suppose I have the following database set.seed(100) base <- expand.grid(grupo = c("a", "b", "c", "d"), score = runif(100)) And that I want to select the lines with smaller score depending on the…
-
3
votes3
answers192
viewsA: Calculate average distance travelled with single tapply
In my view the most elegant way to do this is by using the packages dplyrand tidyr. The code using these functions becomes much simpler to read. It’s worth learning! library(dplyr) library(tidyr)…
ranswered Daniel Falbel 12,504 -
3
votes1
answer618
viewsA: Doubt about conditional (if) in function
The problem with your code is that you are making a comparison with objects that do not exist. In if (pollutant == sulfate), the object sulfate does not exist. You can solve the problem in two ways:…
-
2
votes3
answers21039
viewsA: How do I exclude a set of specific lines, listed in a vector, from a data frame in R?
Suppose you have a data.frame this way: df <- data.frame(a = 1:10, b = 1:10) And that you want to select only the lines 1,5 and 8 that are in the vector: linhas <- c(1,5,8) Then you can select…
ranswered Daniel Falbel 12,504 -
2
votes2
answers239
viewsQ: How to save an error message to a string in R?
I wonder if there is a function that stores the error message of an expression in a string. For example I would like to get the result below: erro <- pegaErro(runif("a")) erro Error in runif("a")…
rasked Daniel Falbel 12,504 -
2
votes1
answer125
viewsA: Mean Difference Hypothesis Test in R Survey Package
The function you will need to use is called svyttest. In the examples, when you use help(svytest) he does it this way: data(api) dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)…
ranswered Daniel Falbel 12,504 -
1
votes1
answer98
viewsA: How to create Abels in a binary vector without it becoming categorical?
That is not possible. What you can do is let the R turn into factor, and when you use the svymean do so: x <- c("sim", "sim", "não", "não") svymean(x = as.numeric(x == "sim"), design = ?) See…
ranswered Daniel Falbel 12,504 -
2
votes2
answers139
viewsA: How to use the svymean() function if I have missings in the observations?
The function svymean has an argument na.rmwhich by default is FALSE, ie if you do not quote the argument in the function call, it will use the value FALSE. If you do svymean(..., na.rm = T) It…
ranswered Daniel Falbel 12,504 -
4
votes2
answers170
viewsA: In R, using dplyr, create a new matrix
Here I think we can use another function of another Hadley package, the tidyr. require(tidyr) data %>% spread(candidato, votos) zona A B 1 1 100 20 2 2 30 15 Note that if you have several…
-
3
votes2
answers823
viewsA: Dplyr and gsub: how to replace parts of one column with another
You can use the str_replace package stringr thus: require(stringr) xis <- data.frame(x1=c("**alo.123", "**alo.132", "**alo.199"), x2=c("sp", "mg", "rj"), x3=c(NA)) xis <- mutate(xis, x3 =…
-
3
votes1
answer206
viewsQ: Order of operations in the R
How does the order of operations in R work? And how can I change them? For example, when I do 1 + 2^2 in the R, he knows that first it is necessary to evaluate the 2^2 and then add the result to the…
rasked Daniel Falbel 12,504 -
8
votes4
answers1143
viewsA: Add rownames as column using dplyr
Julio, I couldn’t think of a solution using the dplyr, but a simple solution that might make the code cleaner is, create a function row_namesas follows: row_names <- function(x, var){ var <-…
-
7
votes3
answers8030
viewsA: How to include lines in a data.frame?
The function rbind make a copy of the data.frameand then add the line, which makes it inefficient. An alternative is to use the function rbind_list package dplyr: linha <- data.frame(x="c", y=3)…
ranswered Daniel Falbel 12,504 -
2
votes1
answer489
viewsA: GLM with random factor in R
You can use the function glmer package lme4. In your case it should stay that way: modelo <- glmer(cbind(visitas, acertos) ~ cor_vantajosa*fase + (1 | id), data = dados, family = binomial)…
ranswered Daniel Falbel 12,504