Posts by Willian Vieira • 3,675 points
78 posts
-
1
votes1
answer1744
viewsA: Change the Section source
You have the option of at least two packages to change the source of sections and subsections. Bundle sectsty: \documentclass{article} \usepackage{sectsty} % Para definir a fonte da seção…
latexanswered Willian Vieira 3,675 -
2
votes2
answers98
viewsA: Language R - Use of function to prevent code repetitions
I don’t know how flexible you want at the level of the two data frames tabela3 and tabela2, but from what I understand you don’t want to repeat the following code:…
ranswered Willian Vieira 3,675 -
6
votes1
answer530
viewsA: R - How to calculate the price change from one period to another?
You can use the function diff(): #dados df <- data.frame(Ano = c(2007,2008,2009,2010), Preço = c(25,30,7,15)) diff(df$Preço) # [1] 5 -23 8 The function diff() ignores the first element. To get…
-
4
votes1
answer67
viewsA: How to transfer a table from the clipboard to a R data.frame
I believe there is a platform problem to import data with ctr-v, so here are two options: For users of Windows: You can use the function readClipboard() for vectors. For example, enter data only…
ranswered Willian Vieira 3,675 -
4
votes3
answers4047
viewsA: A: How to count and sum the amount of a certain "factor" in the observations (lines) of a data.frame?
Using the basic R package: # função para quantificar os 'Sim' func <- function(x) length(which(base[x, c(2:11)] == 'Sim')) # aplicar para todas as linhas base$Total_Sim <- sapply(1:…
-
2
votes1
answer2799
viewsA: Makefile returning "Missing Separator" error
This error is quite common when you use space instead of tab to determine an action. You can check if used tab or space using that command line on the terminal: cat -e -t -v makefile If tab was used…
-
0
votes3
answers91
viewsA: Is it possible to pair values of two dataframes with different observation numbers?
There may be a more efficient way, but if you don’t have many lines it won’t be a problem: for(i in 1: dim(data1)[1]) { data1$Taxa[i] <- data2[which(data2$Estudo == data1$Estudo[i]),…
ranswered Willian Vieira 3,675 -
5
votes2
answers589
viewsA: Latex and Python or R integration
First of all, I’m not familiar with the Python language, so I’m going to focus on the R language. For data handling with R and sql, you can take a look at the package RSQLite which is particularly…
-
8
votes1
answer1340
viewsA: Calculate Time Difference in R
You can use the function difftime, but remember that the dates should be in format in Date-Time or Date. To transform character in Date-Time: Data1 <- "20/01/2018 20:33:58" Data2 <-…
ranswered Willian Vieira 3,675 -
6
votes1
answer42
viewsA: Graph generation error in R
The object Asset is a list. To select each element from this list with inter i you must use double brackets: [[ ]]: # Visualiza gráficos da carteira for(i in 1:length(symbols)){ plot(Asset[[i]],…
-
5
votes1
answer68
viewsA: How to isolate a factor from a result as a vector?
The exit of summary() is a list object. Among the various options, here are two: Option 1: sm <- summary(alba.aov) sm <- unlist(sm) names(sm) # para indentificar o que você quer (no seu caso o…
ranswered Willian Vieira 3,675 -
4
votes3
answers407
viewsA: Delete "X" in Header in R
Try to look at the argument check.names in ?read.csv. read.csv("dados.csv", check.names = FALSE)
ranswered Willian Vieira 3,675 -
4
votes1
answer73
viewsA: Make a matrix of origins and destinations
You can use the function xtabs(): minha_tabela_OD <- xtabs(localidades$Peso_id ~ localidades$Origem + localidades$Destino) minha_tabela_OD #> localidades$Destino #> localidades$Origem A B C…
-
5
votes1
answer243
viewsA: Represent the x-axis of the histogram as the frequency distribution classes?
I could not use your data but here is an example: set.seed(42) x <- rnorm(200, 10) hist(x) Set the desired limit: lim <- seq(from = 6.7, to = 13.7, by = 1) > lim > [1] 6.8 7.8 8.8 9.8…
-
4
votes1
answer1331
viewsA: How to join two data.frames in R with different variables and out of order?
I imagine you want to join the two data frames by columns. The function rbind() (Row r) uni by lines and function cbind() (c of column) by columns. To use the function cbind(), will have to order…
-
4
votes2
answers530
viewsA: Filter Different Texts in R
Some logical arguments of the R language to filter data are important to know: !x => nonx x | y => x or y x & y => x E y isTRUE(x) => test if X is true Filtering data with multiple…
-
5
votes1
answer92
viewsA: Functions R - Strange Character
You are using the function table() which results in an object table R containing a name for each dimension. For example, with the following Matrix m: m <- matrix(1:8, 4) > matrix(1:8, 4) [,1]…
-
3
votes1
answer3746
viewsA: How to change the font on a chart in R?
windowsFonts(Times=windowsFont("Times New Roman")) library(ggplot2) ggplot(data = diamonds, aes(x = carat, y = price)) + geom_point() + labs(title = "Diamantes: Quilates X Preço") + theme(plot.title…
-
5
votes3
answers5016
viewsA: Replace NA in R language
Assuming your dice are on one data frame called dat, and that the column you want to replace the NA is called TIPO: dat$TIPO[which(is.na(dat$TIPO))] <- "TESTE" According to your data, I don’t see…
ranswered Willian Vieira 3,675 -
5
votes2
answers164
viewsA: How to check if a certain sequence of Elements exists in R?
Library(zoo) vectory <- c(3,3,1,1,1,2) which(rollapply(vectorx, length(vectory), identical, vectory)) If the output is any number, the sequence vectory is present in the vectorx; otherwise the…
ranswered Willian Vieira 3,675 -
3
votes2
answers233
viewsA: Plot time series on defined scale
plot(time_series_total, v1, type = 'l', col = "red", xlab = "tempo", xaxt = "n") lines(x = time_series_total, y = v2, col = 'blue') legend("topright", legend=c("v1", "v2"), col=c("red",…
-
1
votes2
answers692
viewsA: How to reverse the order of labels on a bar graph stacked with ggplot2?
To reverse the order I just added one - before Percent. To add % after the values, you can use the function paste(). ggplot(data=percent.prod, aes(x=Ano, weights=-Percent)) + geom_bar(aes(fill=Tec),…
-
6
votes1
answer440
viewsA: Strata R function not found (Ubuntu)
Some functions we use in R are not associated with base package. So we should install the package that developed the function we want using install.packages("nome do package") and then call the…
ranswered Willian Vieira 3,675 -
4
votes1
answer309
viewsA: Saving values for all iterations in R
For each interaction x, y or z, you are defining a new csv. A solution is to simply create a data.frame before the loop and save each interaction in a data.frame: # create an empty data frame…
ranswered Willian Vieira 3,675 -
4
votes1
answer1006
viewsA: How to create a graph with two axes y with different scales in R?
The error is probably in trying to plot "Rainy days" before par(new = TRUE). In addition, after par(new = TRUE) you have to create a new plot() to then plot lines with the lines(). I tried to modify…
-
2
votes1
answer241
viewsA: How to create png file for multiple charts using X11 in R?
x11() is a function to create a new graphical window in R. For multiple charts in the same window, you use the option mfrow = c(x, y) within the function par() (What you’re already wearing).…
-
2
votes2
answers126
viewsA: Loop to calculate maximum value
Maxconsumo<-c() Dia = 1:8 Consumo = c(245, 256, 300, 450, 245, 256, 300, 450) data <- data.frame(Dia, Consumo) for (i in 1:length(Consumo)) { Maxconsumo[i] <-…
ranswered Willian Vieira 3,675 -
3
votes2
answers109
viewsA: How to add a column
First, your question is not reproducible. Next try putting part of the data so we can reproduce the error. Answer You can’t use it $ in a Matrix, because a Matrix is just a vector with dimensions.…
ranswered Willian Vieira 3,675