Posts by Daniel Ikenaga • 729 points
24 posts
-
2
votes2
answers42
viewsA: Graph error in R: "invalid color name"
Because Human has the typology of Character. If you convert to factor you can make the feature identification in Plot by colors. tibble[,14] [87 × 14] (S3: tbl_df/tbl/data.frame) $ name : chr [1:87]…
-
2
votes2
answers39
viewsA: Picking a vector within an R matrix
I wouldn’t do it this way, but correcting your solution: get_neighbor <- function(x, m, k){ len <- dim(m)[1] if (k > len){ return("The k is higher than ...") } else{ for(i in 1:len){ m1…
-
3
votes2
answers78
viewsA: Tables type GT not printing inside loop in Rmarkdown
Rscript does not locate Pandoc, you need to set in the execution file. Check the pandoc directory with the function Sys.getenv("RSTUDIO_PANDOC") I made some simplifications in the example. Rscript…
-
3
votes3
answers56
viewsA: How to Capture a File Extension in R
You can use regex through the package stringr The parenthesis defines the text extract part \w+ defines it to be a word $ defines that it is at the end of the string library(stringr) arquivo <-…
ranswered Daniel Ikenaga 729 -
1
votes2
answers59
viewsA: How to gradually transform n number generation in normal distribution in R
Complementing the idea of user2332849 and filling to observe the convergence. qt.inicial <- 10000 qt.final <- 1000000 num.passos <- 2000 n <- round(seq(qt.inicial, qt.final, length.out =…
ranswered Daniel Ikenaga 729 -
1
votes1
answer326
viewsA: How to adjust margins on R markdown
Include below YAML the code below (YAML is the Rmarkdown header): <style type="text/css"> .main-container { max-width: 90%; margin-left: auto; margin-right: auto; } </style>…
-
2
votes2
answers96
viewsA: Convert a list with different line dataframes into independent dataframes
You can generate your dataframes from a for. a <- list(cars = cars, mtcars = mtcars, CO2 = CO2) for(i in 1:length(a)) { assign(labels(a)[i] , a[[i]]) } To create as a function, simply add the…
ranswered Daniel Ikenaga 729 -
5
votes1
answer223
viewsA: Is there an R function that helps me locate the fashions of a multimodal dataset?
Correcting the function of this site, https://www.r-bloggers.com/lang/portuguese/517 : statmod <- function(x) { z <- table(as.vector(x)) names(z)[z == max(z)] } a <-…
-
1
votes1
answer806
viewsA: how to calculate the average of only one part of a Rstudio column
There is a problem in the import, your data is not in numerical. Setting the example: data <- data.frame(x1 = 1:10, x2 = 11:20) Example of non-numerical data: data$x1 <- as.factor(data$x1)…
-
0
votes3
answers407
viewsA: Delete "X" in Header in R
The problem is that R does not accept the variable name, function or column of data.frame starting with numeric, point or subtraction. That’s why it adds the X. data <- data.frame('1.2_cidade' =…
ranswered Daniel Ikenaga 729 -
0
votes3
answers3012
viewsA: Aggregate function on R
It was unclear how you wanted the result, so I made the two possible solutions for the quantity column. Summing values according to quantities: aggregate((VALOR * QTDE) ~ REFERENCIA + GRUPO_COPA +…
-
3
votes1
answer55
viewsA: Delete totalizing lines
The simplest way is to use a logical vector to select your lines: data <- c("2", "Curso 1", "Turma A", "Manha", "5", "2", "Curso 1", "Turma A", "Tarde", "5", "2", "Curso 1", "Turma B", "", "5",…
ranswered Daniel Ikenaga 729 -
1
votes1
answer102
viewsA: Navigate between pages from a web page bar
There are several ways of solution, in this check if there is content in tags <td>. Note that the output of Tabela1 is 180 (total table data) in size and the table2 is 0. So you can use the…
-
5
votes2
answers326
viewsA: Regular Expression R
Complementing the example of Henry: Selects all fields that have "1". txt[grep("1", txt)] Selects all fields that have "1" or verbatim "First". txt[grep("1|primeiro", txt, ignore.case = TRUE)]…
-
0
votes2
answers85
viewsA: Multiple Gather with 4 resulting "joint" columns
Using as a basis the result obtained from your function Gather, I made a comparison of the columns to get the new data.frame. Note that I create a logical comparison vector of the numbers contained…
ranswered Daniel Ikenaga 729 -
5
votes1
answer163
viewsA: In a matrix Z of elements (i,j) how to assign the value 1 when i=j? (software R)
I do not see a simple form of resolution from your question. But I propose two forms of resolution: Assign the desired diagonal value directly. a <- matrix(rep(0,100), nrow = 10) diag(a) <- 1…
-
2
votes1
answer38
viewsA: error in server rselenium scraping google scholar
Install the XML package install.packages("XML") library("XML")
ranswered Daniel Ikenaga 729 -
2
votes1
answer308
viewsA: How to turn my data.frame into a time series?
You can convert this way, but some time series functions require you to use date in posxit format. df <- data.frame("IPCA", "0.0526", "0.0442") names(df) <- c("IPCA.X04.05.2017",…
ranswered Daniel Ikenaga 729 -
4
votes1
answer1324
viewsA: Convert numeric date to R
Just define the source of the scale that the function as.POSIXct can make the conversion. data <- c(1436904192, 1490717463, 1491924165) as.POSIXct(data, origin="1970-01-01") [1] "2015-07-14…
ranswered Daniel Ikenaga 729 -
2
votes2
answers273
viewsA: Play ggplot2 graph using multiple facets
The idea of facets is to generate the graphics as partitions (split) of a database. It is therefore necessary to consolidate into a single database. Applying customization to each chart (like your…
-
1
votes1
answer59
viewsA: How to read a file if its name is stored in a variable?
Assuming that all files have the same variable structure and can be merged with each other, the code below should work. If the imported files are xls, or another format, they can be parameterized by…
-
3
votes2
answers186
viewsA: How can I transform a variable(0-10) into 3 categories?
A simple and easy to understand way is by using the logical vectors of data analysis. Vectors generate TRUE/FALSE values that validate the next execution. In this example, the data is in a…
ranswered Daniel Ikenaga 729 -
1
votes1
answer384
viewsA: Compare rows of matrices with different dimensions and return a single logic vector
Corrected - For the test to be done simultaneously in a matrix it is necessary to check in a second step using the function ALL(): a <- matrix(1:50, ncol = 2) b <- a[seq(1,25, 2), ] a%in%b # o…
-
3
votes2
answers135
viewsA: Webscrape Scoring for Welfare
To import the data on the Social Security Scoreboard, infographic of the Estadão site and export to Excel, use the code below. If you have not installed the 'XML', 'xlsx' and 'stringr' packages, run…