Posts by Marcus Nunes • 17,915 points
372 posts
-
4
votes2
answers226
viewsA: How to add space in "boxplot" and center the middle
I believe the code below can help you. ggplot(dados, aes(x=warfare, y=Abund, group=warfare:habitat_F_S, colour = as.factor(habitat_F_S), fill=habitat_F_S)) + geom_boxplot(outlier.shape = NA,…
-
3
votes2
answers75
viewsA: How to change the value of a variable?
If the numeric variable calls x, do x <- as.character(x)
ranswered Marcus Nunes 17,915 -
4
votes1
answer454
viewsA: Panel graphics in ggplot2
I have a graphic suggestion just below. I will post my code, the result obtained and then make some comments: library(ggplot2) dados <- read.table(file="data_fran.csv", sep=";", header=TRUE)…
-
8
votes1
answer546
viewsA: Boxplot in R pattern
As no data was provided to solve the problem, I will use the data set iris to solve it. This data set has 150 observations on 4 quantitative variables and 1 categorical. This categorical variable…
ranswered Marcus Nunes 17,915 -
8
votes2
answers558
viewsA: How to make concentric circles in r Plot
Use the command draw.circle package plotrix: x <- seq(-3, 3, by=0.01) y <- x^2 plot(y ~ x, asp=1, type="l") library(plotrix) draw.circle(1, 1, 1, border="red") draw.circle(1, 1, 2,…
-
7
votes1
answer595
viewsA: Import multiple excel tables at the same time
First, let’s create a vector with the names of all your files .xls: arquivos <- list.files() arquivos <- arquivos[grep(".xls", arquivos)] The first line above lists all the files in your…
-
3
votes1
answer119
viewsA: Shiny error when generating HTML
Apparently the problem was both if chained. I took one of them and replaced it with a else. It’s all right now. If it’s in your interest to expand this calculator to more distributions, just add…
-
5
votes2
answers1750
viewsA: How to create a for in R with the indexes of a data frame
The key point here is to realize that for in the R is executed from an index vector. See example below: for (j in 1:5){ print(j^2) } [1] 1 [1] 4 [1] 9 [1] 16 [1] 25 To make this loop, I implicitly…
-
1
votes1
answer55
viewsA: A: Spatial analysis with spatstat, sidebar does not show correct values
Bad News The sidebar is showing the correct data. The function plot(density(shap.lo.ppp,0.02), col=topo.colors(25), main='', xlab='x', ylab='y') is crowding the estimated Gaussian density for…
ranswered Marcus Nunes 17,915 -
6
votes1
answer2565
viewsQ: Extract information from lattes
Introducing Since 1999, Brazilian researchers have had a website where they can post information about their academic career. This information is known as Currículos Lattes. I wish to download a few…
-
4
votes1
answer387
viewsA: How to make a difference in R dates?
The R it needs data with dates to be correctly specified so that it can make calculations that may be necessary. One of the best ways to do this is with the package lubridate: library(lubridate)…
ranswered Marcus Nunes 17,915 -
5
votes2
answers552
viewsA: R - Selecting elements of a data frame with a column that has the same name as a global variable with`dplyr`
Utilize .GlobalEnv$x: library(dplyr) df %>% filter(x == .GlobalEnv$x) x y 1 0 1 2 0 2 3 0 3 4 0 4 5 0 5 6 0 6 7 0 7 8 0 8 9 0 9 10 0 10…
ranswered Marcus Nunes 17,915 -
6
votes2
answers171
viewsA: Identify cases with multiple conditions in multiple columns in R
Use the command fluxo[, 2:5]==43 Thus, each position of columns 2 to 5 will be tested to see if they are equal to 43. Thus, an object will be created with TRUE and FALSE. head(fluxo[, 2:5]==43)…
-
5
votes1
answer730
viewsA: how to place histogram values on top of bar
As far as I know, more advanced graphic packages from R, as lattice and ggplot2, do not have an easy way to place numbers on top of histogram bars. I imagine it can be done, but it’s a pretty big…
-
5
votes1
answer761
viewsA: How to transpose rows into columns (and vice versa) and save to a new database?
Use the function t: dados <- head(cars) dados speed dist 1 4 2 2 4 10 3 7 4 4 7 22 5 8 16 6 9 10 t(dados) 1 2 3 4 5 6 speed 4 4 7 7 8 9 dist 2 10 4 22 16 10 The R has several ways to save data in…
ranswered Marcus Nunes 17,915 -
3
votes1
answer587
viewsA: How to group information into a data frame from missing data?
You can solve this problem with the package dplyr: dados <- structure(list(date = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("1961-08-21", "1961-08-22", "1961-08-23"), class =…
-
5
votes1
answer505
viewsA: How to upload data to Chunk?
Use the rmarkdown to create a report implies to merge the textual part of the analysis with the codes in R. Therefore, it is necessary to explicitly load each package or file needed to perform the…
-
4
votes2
answers589
viewsA: Latex and Python or R integration
In this case, the best solution is to use the rmarkdown. To get an idea of how it works, open Rstudio and go to the menu File > New File > R Markdown... Choose Document and PDF options (note…
-
2
votes1
answer893
viewsA: Sum of the regression square of R models
Once, right here in Stack Overflow, I commented on variable selection (link to the publication). The variable selection problem is similar to the model selection problem: we are trying to choose the…
-
5
votes1
answer201
viewsA: Truncation of values in R
I don’t know any native R function that does this, but I quickly created a function that I believe will do what you want: arredondamento <- function(x){ floor(100*x)/100 } I used your example on…
ranswered Marcus Nunes 17,915 -
5
votes1
answer735
viewsA: Sort of Dates ggplot2
My suggestion is that dates in the R are always represented in the format yyyy-mm-dd. This makes it much easier to work with the software when working with this type of data. He needs to understand…
-
7
votes1
answer139
viewsA: Degrees of freedom Anova R
The Dose column is a numerical value of the type int, not a factor: dados <- S.alba str(dados) 'data.frame': 68 obs. of 3 variables: $ Dose : int 0 0 0 0 0 0 0 0 10 10 ... $ Herbicide: Factor w/…
-
5
votes1
answer1025
viewsA: Variables selected in GLM being used in GLMM
in the models that I have tested in my work, what presents the best result (AIC BIC etc) is not the GLMM that started from all the variables that I have, but the GLMM that starts from the most…
-
6
votes1
answer1063
viewsA: How to add margins and text to the chart (Plot)?
By default, the R considers that his plot creates four axes: axis 1 (x-axis equivalent, with defined scale) axis 2 (equivalent to y-axis, with defined scale) axis 3 (x-axis parallel, no defined…
-
7
votes1
answer1011
viewsA: How to remove caption in Plot?
Place the argument legend=FALSE at the command of your chart: plot(curva5r, ylab= "Dose (%)", xlab = "Dose (g.e.a. de glyphosate ha-1)", legend=FALSE) Reproducible example with a data set of the…
-
4
votes1
answer301
viewsA: A: Subtitles overlaid [ggplot2]
The Warning you receive when making this chart already tells you what is occurring: Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale. That…
-
4
votes1
answer316
viewsA: Predict function in GLMM
The problem lies in the declaration of the new dataset to be foreseen. In some cases (which unfortunately I can’t tell you exactly what they are), the package lme4 requires that factors be used to…
-
8
votes1
answer698
viewsA: Initial values in function nls in R
The function nls is used for nonlinear regression. It uses iterative processes to obtain estimates of the parameters of your model. In theory, these iterative processes gradually approach the real…
-
5
votes1
answer176
viewsA: Filter in dplyr constrained by the maximum variable value of db Gapminder
The result is correct. The command gapminder %>% filter(year == 2007, gdpPercap==max(gdpPercap)) will return all lines of the data frame gapminder which occurred in the year of 2007 and whose…
ranswered Marcus Nunes 17,915 -
4
votes1
answer334
viewsA: How to plot a plot with ggplot
Your problem is in the organization of the data frame sk. The ggplot2 is a very demanding package with the form of the data to be plotted. The ideal is that one column has all the values of gene…
-
3
votes2
answers79
viewsA: Join for unequal records in R
Use the function anti_join package dplyr: library(dplyr) anti_join(funcionarios, empregados) It will give a Warning message, but do not worry. It is irrelevant in this case.…
-
4
votes1
answer35
viewsA: Number of queries in a dataframe
First I’ll use the function diff to calculate the difference between two consecutive columns. It is necessary to transpose the result to be in the same pattern as base: diferencas <-…
-
5
votes1
answer1755
viewsA: How to import multiple excel tabs at the same time?
The first thing to do is install the package readxl, through the command install.packages("readxl") This step only needs to be done once. With the package readxl installed, it is necessary to load…
ranswered Marcus Nunes 17,915 -
5
votes2
answers899
viewsQ: Renaming the levels of a factor based on a data frame
Suppose I have the date frame iris, present in the memory of R: head(iris) Sepal.Length Sepal.Width Petal.Length Petal.Width Species 1 5.1 3.5 1.4 0.2 setosa 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3…
-
3
votes1
answer1848
viewsA: Select part of Text in R
The packages dplyr and stringr can help you in this. First, I will create the dataset: NOME <- c("LEITO 1", "LEITO 2 - HPP", "LEITO 3 - HPP", "LEITO 4") VALOR <- c(10, 20, 30, 40) dados <-…
-
4
votes2
answers233
viewsA: Plot time series on defined scale
For me, the issue of axis Labels is easier to solve using the package ggplot2 to chart. For this, you must first prepare your data so that it is in three columns: sinal, with the values of each…
-
10
votes1
answer514
viewsA: Count sequences of 1 within vector in R
The function rle is perfect for this. It counts exactly the number of lengths and sequence values in a vector: x <- c(1, 1, 0, 0, 1, 0, 1, 1) contagem <- rle(x)…
-
3
votes0
answers287
viewsQ: One of my Shiny applications is not running on my server
I recently installed Shiny on a server I have. This can be checked by clicking at this link. I would like to put on this server several applications that I have done and still intend to do, as if it…
-
5
votes1
answer274
viewsQ: Automatically identify points of influence in a regression
Whenever we make a linear regression, we need to verify that the hypotheses assumed for the model are correct. One of the best ways to do this is through diagnostic graphics. See the example below:…
-
9
votes2
answers396
viewsA: Why are loops slow in R? How to avoid them?
Excellent questions. Below I will put my two cents on them. 1. Why loops are slow in R? Loops are slow in R because this is an intrinsic feature of interpreted languages. Any code written in the R…
-
2
votes2
answers1516
viewsA: How to create column from data contained in other columns
The hardest part was made. Now just choose the contents present in dic.busca.indice.periculosidade inside the column reclamacoes.titulo. Just rotate…
-
1
votes1
answer55
viewsA: Read SQL Microft Exported File 2016
In theory, any. txt file can be imported into the R. Try to rotate the command dados <- read.table(file="NomeDoArquivo.txt", header=TRUE, sep="\t") in which file="NomeDoArquivo.txt" is the file…
-
3
votes1
answer2369
viewsA: Stacked Bar Graph - Labels and Sort - GGPLOT
When working with the ggplot2, I am of the opinion that all transformations to be performed on the data should be done outside the Plot command itself. It is my personal opinion, because I think…
-
7
votes1
answer1047
viewsA: How to generate a sequence of dates in r?
Through function seq: datas_dia <- seq(from=as.Date("2011-07-01"), to=as.Date("2011-10-31"), by="day") datas_semana <- seq(from=as.Date("2011-07-01"), to=as.Date("2011-10-31"), by="week")…
ranswered Marcus Nunes 17,915 -
4
votes4
answers129
viewsA: Build database
I would solve this problem as follows using the R. I’ll set the number of lines in my database: n <- 200 I will create n random values for precipitation, temperature and presence of snakes with…
-
4
votes1
answer1088
viewsA: Select the highest value of a column set of a df and take the column name of that highest value in R
Without using any extra packages, I would solve it as follows. First, I find out which column has the highest value. This response is given by the position of the column: x <-…
ranswered Marcus Nunes 17,915 -
4
votes1
answer152
viewsA: How to separate a time series basis into periods
This problem can be solved with the packages tidyr and dplyr. library(tidyr) library(dplyr) dados.completos <- dados %>% select(-X) %>% complete(Hora=0:23, Animal, Dia, fill = list(Consumo…
-
4
votes1
answer688
viewsA: Error in Plot.window(...) : need Finite 'ylim' values
The minimum of data1$microalb is zero. Therefore, log(min(data1$microalb)) = -Inf. Spin summary(log.microalb) to confirm this. Delete the infinite information from your dataset. A common way to do…
-
5
votes2
answers101
viewsQ: Complete observations in a data frame
Suppose I have the following data set: dados <- structure(list(Ano = c(2001L, 2001L, 2001L, 2002L, 2002L, 2002L, 2003L, 2003L, 2003L, 2004L, 2004L, 2004L, 2005L, 2005L, 2005L, 2005L), Categoria =…
rasked Marcus Nunes 17,915 -
3
votes1
answer8943
viewsA: Doubt about Latex image reference
One way to solve this problem semi-definitively is to use the commands together \ref and \subref: \documentclass[jou,apacite]{apa6} \usepackage[brazil]{babel} \usepackage{color} \usepackage{subfig}…
latexanswered Marcus Nunes 17,915