Posts by Marcus Nunes • 17,915 points
372 posts
-
2
votes2
answers1264
viewsA: Calculation at a specific value of a dataframe?
My first step here is to replace the commas with dots. For example, the R does not consider 1.54 a number. This is a string for the program. Therefore, it is necessary to do this first step. The…
ranswered Marcus Nunes 17,915 -
2
votes4
answers4556
viewsA: How to change the order of appearance of Columns in a Data Frame?
Assuming the data frame is called df: library(dplyr) df_ordenado <- df %>% select(Indice, Produto, Classificação, Comun, Quilo) df_ordenado
ranswered Marcus Nunes 17,915 -
3
votes1
answer1345
viewsA: How to keep only Dataframe-specific lines?
First of all, I would do a little cleanup on your dataset legumes. Note that the header does not have names with intuitive meaning and its first line has something that could replace this header:…
-
5
votes2
answers726
viewsA: How to rename the database (Rdata) in R?
Upload the file banco2_2.rdata in the R. Use the command banco2_2 <- banco2 to create the data frame banco2_2. Upload the file banco2.RData in the R. The banco2 old will be replaced. Merge…
-
2
votes1
answer1029
viewsA: Creation of Boxplot in ggplot2
For some unknown reason, your files df2, df3 and df4 are wrong. See, for example, what happens when I calculate the median of each group, using df1, df2_original (which is yours df2) and df2_correto…
-
6
votes2
answers422
viewsA: Code for viewing Boxplot in ggplot2
The problem is in the order of the object x-axis factors d. The chart g1 with your code is like this: library(ggplot2) library(dplyr) set.seed(123) n=100 #N=100 m=matrix(ncol=8,nrow=n) for(i in…
-
4
votes1
answer215
viewsA: Error when trying to extract table from a site by R, how to resolve?
My little experience with web scraping on R made me like the package more rvest than of XML to do this kind of work. So I’ll give you a solution with it instead of a solution with the package you…
-
4
votes1
answer871
viewsA: Area and Line Graph in R with x-Axis as String
I believe the code below solves your problem. library(ggplot2) dados <- read.table(file="resposta.csv", header=T, sep=";") ggplot(dados, aes(x=X, y=custo_med_gerFV_c_financ)) + theme_bw() +…
ranswered Marcus Nunes 17,915 -
-1
votes1
answer967
viewsA: Interpretation of Impulse Response Charts
Answers lowers were given assuming that Y1 and Y2 equal to zero means the answer is not meaningful. Short answer: Your charts are 95% confidence intervals built through bootstrap. A golden rule of…
ranswered Marcus Nunes 17,915 -
5
votes1
answer3573
viewsQ: Line in a flow chart in Xelatex tikz
Below is the code and the result of the flowchart I’m building: \documentclass{article} \usepackage{tikz} \usetikzlibrary{shapes,backgrounds} \begin{document} \begin{figure}[!ht] \centering % Define…
latexasked Marcus Nunes 17,915 -
3
votes1
answer84
viewsA: Similarity of elements in different vectors
The result of lapply(A, B, FUN = f) is a list. Run B[unlist(mm)] that the result will be the desired: [1] "Porto Alegre - RS" "Porto Alegre - RS" "Brasília - DF" [4] "Fortaleza - CE" If you want to…
-
5
votes1
answer2161
viewsA: Concatenate two columns of an array into a string of characters
Your answer is almost there. Instead of just selecting a matrix line, with the command paste(m[1, 1], m[1, 2], sep = " - ") select all at once: paste(m[, 1], m[, 2], sep = " - ") [1] "1 - A" "2 - B"…
-
6
votes2
answers12366
viewsA: How to sum the values of selected columns of each observation (row) in R?
Use the function apply restricted only to columns that matter in your database. For example, using the object USArrests as an example, the command USArrests[, 1:3] will display only the first three…
ranswered Marcus Nunes 17,915 -
1
votes1
answer212
viewsA: Strsplit regular expression
I solved the problem without regex. cid <- c("cidade1..SP.Brasil", "cidade2...SP.Brasil", "cidade3..SPDF.Brasil", "cidade4...SPDF.Brasil") primeiro <- function(x){ return(x[[1]]) }…
-
2
votes1
answer304
viewsA: How to insert the values and their frequency in a data.frame, from a set obtained by SAMPLE?
Let X_1, X_2, ..., X_n be a sequence of numbers. Let X = X_1 + X_2 + ... + X_n. If I divide the value of each X_i by X, the sum X_1/X + X_2/X + ... + X_n/X will always have value 1. This is a…
ranswered Marcus Nunes 17,915 -
4
votes1
answer713
viewsA: Logistic regression with non-binary variable
By definition, logistic regression can only be used to adjust models where the answer is dichotomous: yes and no, success and failure, male and female. A data set whose variable response is…
ranswered Marcus Nunes 17,915 -
4
votes1
answer79
viewsA: bRasilLegis [ command "get DetailsDeputed"]
The first thing to do is get the list of deputies, as you well put in the original post: library(bRasilLegis) deputados <- obterDeputados() After that, it’s interesting to see what’s inside the…
-
8
votes1
answer469
viewsA: How to calculate the median when the data is in Chunks?
My intuition says that this problem does not have an exact solution as in the case of the average. Thinking of a simple case with two samples x and y, where x <- c(1, 1, 1) y <- c(1, 2, 3) We…
-
2
votes1
answer1008
viewsA: Histogram R. Changing the values of the axes!
The trick here is to realize that it is possible to make a traditional histogram and save the information relating to its construction on an object. For example, pontos <- c(0.6666667, 1.0000000,…
-
1
votes1
answer580
viewsA: Graph ggplot axis x
I believe the code below solves your problem: n <- length(datamatrix$value) datamatrix$Index <- 1:n ticks <- floor(seq(1, n, length.out=10)) rotulos <- format(datamatrix$Diff[ticks],…
-
2
votes1
answer1954
viewsA: Contingency table in R
Try to rotate the commands with > ahead, assuming that your data is within a data frame called df: > library(reshape2) > acast(df, Destino ~ Proposito, fun.aggregate=sum) Using Custo as…
-
4
votes3
answers2121
viewsA: Add line at the end of the file with the sed command
You can also solve this problem without using the sed: sudo echo $JAVA_HOME=/usr/lib/jvm/jdk7u79 >> /etc/profile
-
4
votes1
answer650
viewsQ: Interaction graph in ggplot2
I’m trying to adapt some standard R graphics to the style of ggplot2. One of the graphs for which I intend to do this is the interaction graph in a linear model adjustment study. The following data…
-
5
votes2
answers256
viewsQ: Sort the k highest results using dplyr
I can select the k greatest results from a table in R. For example, if k equals 5, I get the following result: library(dplyr) library(ggplot2) top_n(mpg, 5, wt=displ) # A tibble: 5 × 11 manufacturer…
-
3
votes1
answer138
viewsA: I can’t install the stringi package on Centos
I discovered the problem. When rotating strings /usr/lib64/libstdc++.so.6 | grep CXXABI receive the output CXXABI_1.3 CXXABI_1.3.1 CXXABI_1.3.2 CXXABI_1.3.3 CXXABI_1.3.4 CXXABI_1.3.5 CXXABI_1.3.6…
ranswered Marcus Nunes 17,915 -
3
votes8
answers3166
viewsA: Fewer moves from a horse to a given house in Chess
I’m not an expert on python, but I have a small notion of graph theory. This kind of problem can be solved using Algorithm by Dijkstra. According to Wikipedia, it is used for the following: A…
-
5
votes1
answer138
viewsQ: I can’t install the stringi package on Centos
I’m trying to install the package stringi in a cluster that rotates Centos 7, but I am failing miseravelvente. The error that occurs is below: ** testing if installed package can be loaded Error in…
rasked Marcus Nunes 17,915 -
2
votes1
answer466
viewsA: Label does not appear on the chart
Your example is not reproducible, because we do not have access to your data. I imagine that increasing the limit of the axis y solves your problem: barplot(table(var_check), main="Unidade da…
-
4
votes1
answer60
viewsA: Plot Main Title with Text and formula y = a + betaX + Epsilon
Use the functions expression and atop within the argument main of plot: plot(a, main=expression(atop("Curva da Vida dos Genes Fluxo Vida", paste("Y = " , alpha, " + ", beta, "X", " + ", epsilon))))…
-
2
votes1
answer600
viewsA: Get different values from a column - Data Frame - R Language
Assuming the data frame is called x, the control to be used is table(x$to) This will create a table with all the unique values of this column and the number of times each of them appears.…
ranswered Marcus Nunes 17,915 -
3
votes1
answer428
viewsA: Weighted linear regression using the inverse of variance as the weighting factor
Just create the desired weight array to solve this problem. In your case, I called this vector pesos: variancias_condicionais <- aggregate(df$Y, list(df$X), var)$x quantidade_X <-…
-
1
votes0
answers43
viewsQ: I cannot install ruby 2.3.2 on Centos without root privilege
I need to install ruby on a server with Centos 6.5. I don’t have root access, so I can’t use yum. I downloaded the source file, unzipped it into a folder called ~/software and rode ./configure…
-
3
votes1
answer82
viewsA: Graph of Conditional Densities of a Linear Regression
Follow a code suggestion to make this chart: # fazer a regressao com esta sintaxe evita # erros e warnings com a funcao predict ajuste <- lm(Y ~ X, data=data) # medias de cada Y previsto X <-…
-
2
votes2
answers57
viewsA: use of ifelse with Matrix
I thought to solve this problem without using ifelse. I have not tested to see if this code is more optimized or not. Replace the last line of your code with the following three lines: gr2 <-…
ranswered Marcus Nunes 17,915 -
5
votes1
answer36
viewsA: Convert labels to numeric labels
Transform your vector a in factor and then convert it to numeric: as.numeric(factor(a)) [1] 1 2 1 1 3 5 4 1 2 It is even possible to assign different numerical values to the levels of a. For…
ranswered Marcus Nunes 17,915 -
4
votes2
answers534
viewsA: How to plot multiple charts on several different pages using ggplot
I generated some random data to be able to make this graph. I believe the code below will solve your problem. library(ggplot2) Data <- data.frame( Subject=factor(rep(c(1:10), each=32)),…
-
1
votes1
answer99
viewsA: use of Sys.Sleep
Point-to-point graph would be a graph like an animation? If so, the code below solves your problem: # criacao as variaveis e calculo do flux n <- 1 Cn <- 6.45 x <- 3 t <- seq(1, 20) flux…
-
4
votes1
answer53
viewsA: Integrating columns of an Array using R (Error)
The function integrate does not use to compute integrals this way. To specifically use this function, you need to write the function to be integrated into R. In your case, as the function values are…
-
6
votes1
answer1695
viewsA: Calculating T-Student Probabilities in R
I should not make this calculation in any of these ways. The way it is formulated, the question does not seem to me to make much sense. The Student t distribution is always centered at zero (unless…
-
2
votes2
answers228
viewsA: Filtering data from a vector
One way to do this is with the package ggplot2: library(ggplot2) data(mtcars) ggplot(mtcars, aes(x=as.factor(cyl), y=mpg)) + geom_boxplot() + labs(x="Cilindros", y="Milhas por Galão") For this to be…
ranswered Marcus Nunes 17,915 -
4
votes1
answer2281
viewsA: Select a part of the database in R
I could not read the data with your original commands. I changed them so that my computer could work. If you can read these files with your original commands, ignore this part of my code.…
-
7
votes1
answer114
viewsA: Building a function by defining x and y using R
This is what you want to do Riemann sum. I would use an idea based on Simpson’s formula to obtain this result: library(Bolstad) integral <- sintegral(matrix[, 1], matrix[, 2]) integral$value [1]…
ranswered Marcus Nunes 17,915 -
2
votes1
answer1228
viewsA: Calculating Integral using R
According to what I understood about your problem, I believe it cannot be solved. Note that Thus, the integral is undefined between 0 and 0.5. It diverges in this interval. It would be like…
-
5
votes1
answer219
viewsA: Probabilities with pnorm R function
Yes, you’re doing everything right. If we stick to the theory, yes, these two results should be the same. If your data comes from a normal distribution, these two values should be equal. (more…
ranswered Marcus Nunes 17,915 -
1
votes1
answer60
viewsA: Checks for a vertex in R
The question is a little fuzzy, but this is what you’re looking for? library(igraph) g <- graph.full(n=10) # cria grafo completo, com 10 vertices V(g) # 10 vertices numerados de 1 a 10 TRUE %in%…
-
7
votes2
answers2782
viewsA: Is there a difference between assigning value using '<-' or '=' in R?
There is no difference in the vast majority of cases. Commands x <- 5 and x = 5 are identical. However, if you want to assign arguments to a function, you are required to use =. For example, to…
-
3
votes1
answer240
viewsA: Linear regressions in IHD with subdivided plot
The first thing to do when we analyze an experiment is exploratory data analysis. It wasn’t explicit in your question, but I’m assuming that Fator1 concerns the plots and Fator2, the sub-plots.…
-
2
votes2
answers1801
viewsA: How to join two csv files in R?
I believe the code below solves your problem: aux <- dados_2[!(dados_2$Ins %in% unique(dados_1$Ins)) | !(dados_2$A %in% unique(dados_1$A)), ] dados_final <- rbind(dados_1, aux) The data frame…
-
1
votes1
answer55
viewsA: Prolema with R Studio layout
This is not Rstudio. This is pure R, no IDE. Download Rstudio Desktop at this link and be happy.
ranswered Marcus Nunes 17,915 -
2
votes1
answer252
viewsA: multiple columns using geom_lines ggplot
The ggplot2 requires the data to be in long format or Narrow, depending on the source. So the trick in your problem was just to convert the data set to long, make a little manipulation in the result…