Posts by Guilherme Parreira • 2,060 points
68 posts
-
1
votes1
answer69
viewsA: Plot half-normal chart for mixed models adjusted with nlme package
Alternatives to your problem: You need to program a function for the nlme::lme work with the package hnp. That’s what the mistake is suggesting. I have never worked upon that possibility, but the…
-
0
votes1
answer305
viewsA: Automate script execution R
This is not a complete answer, but I think it can help you. I don’t use Windows, so I can’t properly test. A possible solution to the accent problem: Inside the R script, instead of you writing the…
-
6
votes4
answers285
viewsA: Separate data by values on the line?
You can use split: data = data.frame(comprar=comprar, custo=custo) Y = split(data, data$comprar) For each different level of comprar you’re gonna have a data.frame within a list: $a comprar custo 1…
-
1
votes1
answer33
viewsA: Strategy to run regressions with many iterations without much RAM
If you are on Linux, you can run htop in the terminal and track RAM memory consumption. But what may be the problem for you is what is described in warning of lavaan: lavaan WARNING: some ordered…
-
1
votes1
answer41
viewsA: Send an e-mail to R
Dude, I also tried to do this last week with this package, and I couldn’t (a specific gmail problem is that it doesn’t let third-party apps send or receive emails. The other emails should also have…
-
4
votes1
answer130
viewsA: (Language R) How to make the axis of the graphs more detailed in ggplot2?
The values that will be shown in the graph are controlled by scale_y_continuous, just add + scale_y_continuous(breaks = c(seq(0, max(engrep$Reprovações, na.rm = T)+50, 100))) at the end of the code…
-
2
votes1
answer448
viewsA: Error reading file . xlsx in R
the last writing of the worksheet name has some hidden character, which causes the path error. Note that when I select the second name, the first name appears selected, and the third not: Then just…
-
1
votes1
answer62
viewsA: Count occurrence of events traversing columns of a dataframe through a for loop in R
You can try: cols <- paste0("sem", 1:15) as.data.frame(sapply(datafile[,cols], table)) the command sapply makes the table in each of the columns for you, ie the for.…
-
0
votes1
answer62
viewsA: Error: Discrete value supplied to Continuous Scale (error function to position "n" in graph)
I don’t know if it is possible to do this with stat_summary. One option is to use geom_text: ggplot(data = dados3, aes(x = PERIOD, y = NOTA_FINAL)) + geom_boxplot() + facet_grid(. ~ ANO_DISCIPLINA)…
-
2
votes1
answer75
viewsA: Problems automated formatting subsection Rmarkdown in R
Use writeLines("### Teste 03") instead of cat("### Teste 03"). It worked for me
-
2
votes1
answer73
viewsA: Is there a package that does stepwise and multicollinearity analysis simultaneously?
Hard to have a function that does exactly what you want (I don’t know). When you do an AIC stepwise, it will first select the model with the smallest AIC (it does not look for multicollinearity, but…
ranswered Guilherme Parreira 2,060 -
2
votes1
answer55
viewsA: Create a data frame by separating terms from a string into columns
To do this, you can use the function stringr::str_split_fixed: df <- structure(list(V1 = c("WZ_311205_20131007_20131008113131_RUA_RAMAL_FARIA_TEMP_DATA_ _AVENIDA_DADOS_PORTO_9.xml",…
ranswered Guilherme Parreira 2,060 -
5
votes3
answers5381
viewsA: How to replace variables with NA values with ZERO within a date.frame in R?
To replace any column with NA for 0, just do: Dados[is.na(Dados)] <- 0
ranswered Guilherme Parreira 2,060 -
0
votes1
answer48
viewsA: Preprocess function error not found
If installation of the package caret was successfully performed before running the function preProcess, you need to call the package caret, via library(caret). Installation is done only once, while…
ranswered Guilherme Parreira 2,060 -
3
votes2
answers88
viewsA: Create a column with the second highest row value
A faster and simpler way to do it is via apply: cols <-…
ranswered Guilherme Parreira 2,060 -
1
votes2
answers283
viewsA: x-axis for time series in ggplot
n <-data.frame(x = c(NEP$NEPeleitoral), y = c(NEP$`NEP parlamentar`), z = c(NEP$anoeleicao)) ggplot(n, aes(x = n$z, y = n$x)) + geom_line(aes(colour="NEPELEITORAL"), shape=1) + stat_function(fun…
-
0
votes1
answer145
viewsA: dplyr filter() problems
Reply by @Lukais Iohan Carvalho: "Guys, I figured out the mistake. I don’t know why, but R was importing my data as Character, down to the numbers. So I gave this error when filtering the values. I…
-
0
votes1
answer60
viewsA: Function to go to a particular part of the code
You can use the function next. See fictitious example: v <- LETTERS[1:6] for ( i in v) { if (i == "D") { next } print(i) } [1] "A" [1] "B" [1] "C" [1] "E" [1] "F" In your case the v would be the…
ranswered Guilherme Parreira 2,060 -
2
votes3
answers121
viewsA: How to exclude a specific row from a base in R
base_renomeada <- base_renomeada[!base_renomeada %in% c("N", "P", "K"), ] Or if you want to inform those you want to keep: base_renomeada <- base_renomeada[base_renomeada %in% c("S", "M"), ]…
ranswered Guilherme Parreira 2,060 -
1
votes2
answers82
viewsA: What books do you recommend to study on data analysis in R?
There is a very good workbook on R to begin the studies, which is that of Professor Paulo Justiniano: http://www.leg.ufpr.br/~paulojus/embrapa/Rembrapa/ Springer has several books with "with R"…
ranswered Guilherme Parreira 2,060 -
3
votes1
answer410
viewsA: Download a table from a website in data.frame format in R
This response has a lot to do with scraping data from the web and using regular expressions. I’m no expert on the first, I use the second, but I believe I can help you. To download the database, you…
ranswered Guilherme Parreira 2,060 -
6
votes1
answer192
viewsA: How to improve R output
1st Form: Manual I usually get the output of the regression model I want, turn it into a data frame, and for that I count on the help of the package broom. Then I use the table formatting functions…
-
5
votes2
answers104
viewsA: Approximate graphics
To regulate the distance in "height" and "width" between the graphs you need to control the parameter mai inside the command par: par(mfrow=c(2,2), mai = c(0.3,0.3,0.3,0.3)) barplot(1:4)…
ranswered Guilherme Parreira 2,060 -
2
votes2
answers153
viewsA: How to delete and then create all variable names in a data.frame in R?
You’ll have to pass NULL to the names of your data.frame "Excluding": names(iris) [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species" names(iris) <- NULL names(iris) NULL…
ranswered Guilherme Parreira 2,060 -
1
votes2
answers621
viewsA: Remove specific remarks from Data Frame in R
Assuming data be your data.frame: data <- data[!data$T== 2003, ] or if the column is a character: data <- data[!data$T== "2003", ]…
ranswered Guilherme Parreira 2,060 -
2
votes1
answer166
viewsA: How to fix problem with special characters in Knitr::Kable and kableExtra for a PDF report
To solve such a problem, just put: escape = F in kable d<-kable(d, "latex", booktabs=T, row.names = FALSE, align="c", escape = F) Whenever you use a special character, or your function generates…
ranswered Guilherme Parreira 2,060 -
2
votes2
answers74
viewsA: Renaming string text in a column
One of the ways you do this is by using the function ifelse together with the logical operator & and with the subset of strings from substr (so that it is not dependent on the year):…
ranswered Guilherme Parreira 2,060 -
1
votes2
answers52
viewsA: R regression on same line data
It is not possible to adjust the regression model the way you want, because it does not make sense. If you adjust a model for each baseline, vc will have a size 1 sample, and with that, vc will not…
-
4
votes1
answer204
viewsA: R how to calculate on different lines of the date.
The R is a language that allows you to do vector calculations, so just: temp$t <- (temp$ano - 1997) +1 so that the account is applied to all rows of your data.frame.…
ranswered Guilherme Parreira 2,060 -
2
votes1
answer1154
viewsA: How to remove text from a string in a data frame column in r?
You can make use of the following regular expression: gsub("\\s\\-\\s\\S\\S", "", data$Município) In which datais the name of your data frame (if you make your data available through…
-
4
votes1
answer2893
viewsA: Change title and caption colors in ggplot2
Use the arguments color and size within the function labs: ggplot(data=gapminder_2007,aes(x=gdpPercap,y=lifeExp,color=continent,size=pop)) + labs(title="PIB e Expectativa de Vida em 2007",…
-
3
votes1
answer535
viewsA: Import xls file to R
Apparently, you will need to use the function readxl::read_excel to do this job. For this, you will need to download the spreadsheet first and read it in your working directory (as it is not…
-
1
votes1
answer118
viewsA: Rstem package installation on R
You can install directly through the website http://www.omegahat.net/ from the following command: install.packages("Rstem", repos = "http://www.omegahat.net/R")…
ranswered Guilherme Parreira 2,060 -
2
votes1
answer393
viewsA: Correlation graph with coefficients and significance together
I did a similar search of this for some time, and I remade it again, but could not find such a result. So I thought it wouldn’t be an interesting visualization, because no one has done it before and…
ranswered Guilherme Parreira 2,060 -
0
votes2
answers117
viewsA: turn numbers into relative frequency
dat <- structure( list( X = c("Ver_suj", "Ver_obj", "Substantivo", "Adjetivo" ), Bolsonaro = c(59L, 299L, 988L, 653L), Ciro = c(188L, 242L, 128L, 212L), Manuela = c(59L, 66L, 1024L, 629L), Marina…
-
2
votes2
answers492
viewsA: Barplot with labels
Another way to do this is by using ggplot2: Territo <- data.frame(E = c(127, 130, 131, 131, 123, 278, 90, 139, 109, 72, 96, 103, 80, 120, 76, 60, 51), names = c("1", "2","3", "4", "5", "6", "7",…
ranswered Guilherme Parreira 2,060 -
0
votes1
answer90
viewsA: Stem for Twitter
The main function of stemming maid in tm_map is the stemDocument, but as presented in the answer to that question, it is not possible to use the same for Portuguese due to a bug. What I did to get…
-
1
votes1
answer410
viewsA: R - How to calculate the density from the accumulated curve based on the Cox regression model
If such values are the result of your F(x), then you can approximate your fdp(x) from the following equation: where x2 and X1 are the values of "x" you used to calculate your F(x), where x2>X1,…
ranswered Guilherme Parreira 2,060 -
1
votes1
answer510
viewsA: Read and explore dat files through R
Translating and Adapting the Answer from here. First: As a file .dat can store any kind of data, before importing it for the first time it is useful to use readLines to read the first lines of the…
ranswered Guilherme Parreira 2,060 -
1
votes1
answer607
viewsA: ệ log' not Meaningful for factors
‘log’ not meaningful for factors means that you tried to apply the logarithm to an object of the type fator. Example of the problem: nn <- factor("4233") log(nn) Error in Math.factor(nn) : ‘log’…
ranswered Guilherme Parreira 2,060 -
1
votes1
answer612
viewsA: How to leave in a boxplot in R, all x-axis values written in graph?
Possibly this problem of not being able to visualize the boxplots is due to the type of variables. Since both are numerical (from the description of your text), you should not use such a graph. Such…
ranswered Guilherme Parreira 2,060 -
5
votes1
answer88
viewsA: How to chart in r with variable titles?
To get the variable’s real name you need to use deparse(substitute(y)) in the title of the chart: Validação <- function(y){ plot(y, main= paste('Gráfico', deparse(substitute(y)))) } This goes so…
-
2
votes0
answers1095
viewsQ: How to do Descending Hierarchical Classification (CHD)/Reinert method in R?
In the Iramuteq has a very common analysis, which is the Descending Hierarchical Classification (CHD) or also known for reinert’s method. Here is an example of the same:…
rasked Guilherme Parreira 2,060 -
4
votes1
answer391
viewsA: In R, correct typing errors followed by a database processing
Introducing I had a similar problem to this in 2017, and I solved it from the Fuzzy logic, based on this link 2016. In the link, the author explains that he takes each sentence (which in this case…
ranswered Guilherme Parreira 2,060 -
3
votes2
answers222
viewsA: reshape2::melt counter function (unstack)
First, you need to create an identifier variable: dados$id <- 1:nrow(dados) Then, the variables you want to stay in the row need to be on the left side of the formula, and in the right column.…
-
3
votes2
answers61
viewsA: Remove items from a list that are part of a character or part of a certain class
Objective 1: remove Mylist elements containing the particle qu mylist[grep("qu", names(mylist))] Just do a regular expression and look for the term qu. Note that the output is also a lista Objective…
-
6
votes3
answers433
viewsA: geom_text positioning labels individually
What you need to do is use the argument nudge_y of geom_text. You must pass a vector of values of the same length as the original. Follow code: # Cria as posições dat$pos <-…
-
5
votes1
answer1077
viewsA: Execution of multiple functions within loops *pply
The function lapply accepts a single data frame (or list) at a time. Note that however much you enter with a data.frame the function converts the object into a lista. See the function input lapply:…
ranswered Guilherme Parreira 2,060 -
0
votes1
answer161
viewsA: Boxplot of ggplot2 giving error (does not make the boxes, only a few points with some scratches), how to fix? OBS: I made other graphics and it worked, only the one stuck
Your variable varbiom.efs is as character, you need to turn it into numeric (or correct the data, in last case). Put this code before your call ggplot: effectsize$varbiom.efs <-…
-
0
votes1
answer442
viewsA: Create column in R
Very strange this way of storing the database, but anyway, it follows code that does what you need: df <- structure(list(Potreiro = structure(c(3L, 3L, 3L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), .Label =…
ranswered Guilherme Parreira 2,060