Posts by neves • 5,644 points
165 posts
-
1
votes0
answers76
viewsQ: Doubt with the CSS nomenclature
The CSS can be applied in three different ways in a document HTML: within the tag itself (inline): <body> <h1 style='color: red';> Hello World </h1> </body> within the tag…
-
1
votes1
answer71
viewsQ: How to write a shorthand containing several arguments of length?
Consider the shorthand background. With him, I can do it: .variable { background-image: url('image.png'); background-size: 70px 60px; background-repeat: no-repeat; background-position: 95% 50%; }…
-
2
votes0
answers61
viewsQ: Function highcharter::hciconarray does not produce the icons on the chart
The code below is in the documentation of package highcharter to the topic hciconarray: library(highcharter) library(tidyverse) hciconarray(c("car", "truck", "plane"), c(75, 30, 20), icons =…
-
4
votes3
answers2072
viewsA: How to join two data.frames of different sizes per column in R?
Suppose a (10 lines) and b (5-line): a <- data.frame( x = replicate(n = 8, expr = runif(10, 20, 100)) ) b <- data.frame( y = replicate(n = 4, expr = runif(5, 20, 100)) ) Agrora, I create a…
-
4
votes1
answer140
viewsA: How to turn my data.frame variable values into columns in R?
You can use the tidyverse to do what you want. First, create a reproducible example: set.seed(123) df_1 <- data.frame( cod = 1, qtde = sample(x = 1:4, size = 11, replace = TRUE), mes = c(1, 1, 2,…
-
1
votes4
answers1763
viewsA: How to know which is the largest variable of a vector in R?
You can solve the problem with the function sort: sort(colnames(vetor), decreasing = TRUE)[1] [1] "z" Remembering that values must be named.
-
3
votes2
answers5241
viewsA: How to order Ascending and descending in R?
You can use the function sort of R base: sort(base$workclass) To sort decreasingly, you need to insert the argument decreasing = TRUE: sort(base$workclass, decreasing = TRUE) You can also use the…
-
1
votes2
answers373
viewsA: How to calculate the average excluding zeroes in R?
Another solution is to use the function subset: x <- c(12,20,15,0,7,0) mean(subset(x, x != 0)) [1] 13.5 or mean(subset(x, x > 0)) [1] 13.5 However, it is preferable to give preference to the…
-
15
votes1
answer704
viewsQ: What is and what is an anonymous function in R?
What is an anonymous function? And why can it be called função lambda? What is the usefulness of an anonymous function in language R? Where it can be applied (for example, it can be applied in…
-
1
votes1
answer1846
viewsA: Language R: How to get scientific numbers out of graphs?
If your problem is just scientific notation, you can make this adjustment by options. Try this: options(scipen = 999) This high value (999) avoids the return of numbers in scientific notation.…
-
3
votes2
answers80
viewsA: Form Equation in R-Multiple Regression
From what it seemed to me in the comments and the link you posted, your goal is to make an adjunct linear regression of a forecast. Here’s the solution: to) analyzing df <- data.frame( y =…
-
3
votes1
answer1112
viewsA: How to calculate MODA with bimodal value in a date.frame in R?
You can solve this problem with tidyverse. Rather, I create a reproducible example: data <- data.frame( a = c(1, 2, 2, 7, 3), b = c(2, 2, 1, 1, 2), d = c(1, 3, 2, 2, 3), e = c(2, 3, 1, 2, 2) )…
-
5
votes3
answers5381
viewsA: How to replace variables with NA values with ZERO within a date.frame in R?
It is also possible to solve the problem with tidyverse. First, I create a reproducible example: dataset <- data.frame( a = c(NA, 1, NA, 2, 4), b = c(1, 2, 3, NA, NA) ) With dplyr gets like this:…
-
2
votes2
answers88
viewsA: Select first with conditional
With dplyr: library(dplyr) x %>% filter(valordia > 0) %>% arrange(data) %>% slice(1) cod_produto valordia data 2 110.98 2019-01-01 filter filters the values > 0; arrange sorts the…
-
3
votes3
answers952
viewsA: How to filter a range of values?
As @William Vieira quoted in the comments, the crease defined in the question does not exist in the vector cvfm_multr. Anyway, here’s a solution with tidyverse. First of all, I create a data.frame…
-
6
votes3
answers7855
viewsA: When do I use "%d" in a python language?
The %d is a placeholder (position marker). It is used to reserve values (numbers) in a vector. For example: print ('%s comprou %d laranjas' % ('Mikael', 12)) The way out is: Mikael comprou 12…
-
3
votes1
answer98
viewsA: Column of unwanted numbers in write.xlsx
The problem occurs because the function write.xlsx comes with the parameter TRUE in the argument row.names. So you must do: library(xlsx) write.xlsx(df, "buildingTEPT.xlsx", sheetName = "TEPT",…
-
2
votes4
answers188
viewsA: Import Excel file to R
If your problem is specifying the path, try bringing it with the following function: file.choose() It will open the folder menu of your operating system. Take two clicks on the filing cabinet you…
-
2
votes3
answers121
viewsA: How to exclude a specific row from a base in R
With tidyverse you can do so: df <- data.frame( fraude = c('K', 'M', 'N', 'P', 'S'), valores = c(1, 2, 18405914, 1, 111044) ) fraude valores 1 K 1 2 M 2 3 N 18405914 4 P 1 5 S 111044…
-
6
votes2
answers291
viewsA: Convert written numbers with thousands separator to numeric value in R
With stringr you can do this: library(tidyverse) b <- a %>% str_replace_all(pattern = '[.]', '') %>% as.numeric() class(b) [1] "numeric"
-
1
votes1
answer87
viewsQ: How to use the `dplyr::rowwise` function with more than one variable?
Consider the data set below: df_1 <- data.frame( x = replicate(4, runif(30, 20, 100)), y = sample(1:3, 30, replace = TRUE) ) I did the following analysis: library(tidyverse) df_1 %>%…
-
15
votes5
answers1048
viewsQ: What is the use of knowing how to debug a code in R?
According to the theory, debugging can be defined as the art and science of correcting unexpected problems in your code. What is the usefulness (for a data analyst) of knowing thresh a code? What…
-
3
votes2
answers94
viewsA: Select Time in R
You can do it like this: library(tidyverse) library(lubridate) DADOS %>% mutate(DATA_INICIO = dmy_hm(DATA_INICIO)) %>% separate(DATA_INICIO, into = c('DATA', 'HORA'), sep = ' ') In this way,…
-
2
votes1
answer216
viewsQ: Insertion of intervals with the if Else condition structure
Consider the vector and function: j <- 1:10 my_fun <- function(x) { sapply(x, function(x) { if (x == 5) { ('EM ANALISE') } else if (x < 5) { ('REPROVADO') } else if (x > 5) {…
-
18
votes3
answers4338
viewsQ: What is the "line break" in a Regex?
The language I use is R. And, as the theory of Regular Expressions suggests, each language deals differently with line breaks (\n). Consider the following string: text_1 <- c('Olá, meu nome é…
-
6
votes2
answers135
viewsQ: Difference between metacharacters . * and +
Consider this set of strings: my_names <- c('onda', 'ondas', 'ondass', 'ondassssssss', 'ond', 'on') Using the R language, I checked the metacharacters .* and + bring the same information:…
-
4
votes1
answer49
viewsQ: How to change the cut point (cut-off) in glm function?
I have the segiunte database, where I intend to do a logistic regression: set.seed(1) dataset <- data.frame( x = replicate(6, runif(30, 20, 100)), y = as.factor(sample(0:1, 30, replace = TRUE)) )…
-
3
votes1
answer123
viewsQ: Equivalence to kmeans inside Caret::Train
I tried to adjust a model kmeans within the package caret with the function train. But I checked that it is not available. I generated a frame to do this: set.seed(15) d <- data.frame( x =…
-
2
votes1
answer63
viewsA: Tidyr spread does not return to original data
It is necessary to activate the function group_by before mutate, as you quoted @Tomás in the comments. The function would look like this: library(tidyverse) y <- x %>% group_by(factors) %>%…
-
1
votes1
answer63
viewsQ: Tidyr spread does not return to original data
Consider the data.frame: df_1 <- data.frame( a = replicate(6, runif(30, 20, 100)), b = rep(c(LETTERS[1:5]), times = 1, each = 6) ) Use of gather: library(tidyverse) library(magrittr) df_1…
-
1
votes1
answer541
viewsA: Names exchanged in a column: How to replace values in a column by keeping the rest of`data.frame` constant?
You can simultaneously recode the values with the function recode of dplyr. First, I’ll create an object data: library(tidyverse) nome <- c("Foo", "Bar", "FooBar", "Baz") data <- tibble( nome…
-
3
votes2
answers810
viewsA: Convert all columns of a data frame
If you have a list, you can do the following: # Reprodução da lista for (i in 1:6) { assign(paste('var', i, sep = '_'), runif(30, 20, 100)) } dataset <- cbind.data.frame(mget(ls(pattern =…
-
1
votes1
answer243
viewsQ: How to use filter_functions?
I try to use the functions filter_ (all, at, if), but unsuccessfully, mainly for strings. Consider the data set below: set.seed(1234) data_1 <- data.frame( a = c(paste('group', 1:6, sep = '_')),…
-
4
votes1
answer907
viewsQ: When to use the.call function?
Dieferenmente de lapply, do.call applies a function across a list (which is also a data.frame). Consider the loop for down below: set.seed(123) for (i in 1:6) { assign(paste('var', i, sep = '_'),…
-
2
votes2
answers840
viewsA: Group data by a certain column in the R
Using dplyr: library(dplyr) data %>% group_by(continent) %>% distinct(country) %>% count() # A tibble: 5 x 2 # Groups: continent [5] continent n <fct> <int> 1 Africa 2 2…
-
1
votes2
answers71
viewsA: Indexing of Dataframe
With dplyr you can do this: library(dplyr) y %>% group_by(uf1) %>% arrange(desc(mensal)) %>% slice(1) group_by group analysis; arrange sort the data increasing or decreasing (desc); slice…
-
5
votes1
answer423
viewsQ: What is the use of arrays in r?
vector, matrix, data.frame and list are widely used in data analysis and tag peguntas r here in the website. In particular, I see no applicability of array in r. For example: vec_1 <- c(2:4)…
-
6
votes1
answer360
viewsQ: What is the use of the functions with underline (_) at the end?
Consider the functions of the following Packages: dplyr library(dplyr) gorup_by_ summarise_ mutate_ transmute_ tidyr library(tidyr) gather_ spread_ separate_ unite_ What is the usefulness of these…
-
5
votes3
answers673
viewsQ: How to go through the data.frame cases using `dplyr`?
I am trying to analyze the cases (lines) of a data.frame with dplyr, but without success. I created two functions for this: f1 <- function(x) { c(s = sum(x), m = mean(x), v = var(x)) } f2 <-…
-
4
votes1
answer704
viewsA: How to extract the week number of the month in R?
You can use the function lubridate::day together with the function ceiling: library(lubridate) hoje<-Sys.Date() # Sys.Date retorna a data de hoje [1] "2019-02-11" day(hoje) # day retorna o dia do…
-
5
votes4
answers315
viewsA: How to apply several functions to the same object?
Just create a function using the function combine (c): fun1<-function(x){ c(mean=mean(x),sd=sd(x),min=min(x),max=max(x)) } To apply this after function on the desired object: fun1(x) mean sd min…
-
5
votes2
answers1438
viewsA: What is wide/long data?
What does it mean that a table is in wide format? And long? A database in format wide is the one in which the variables are unpaired (one separate from the other). A database in format long is the…
-
4
votes1
answer371
viewsQ: How to use letters instead of numbers within the LETTERS array?
The vector LETTERS works as follows: LETTERS[1:10] [1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" Like adjust this vector to insert letters instead of numbers? Something like: LETTERS[A:J] Error:…
-
6
votes1
answer100
viewsQ: Why is "vector" considered a "list" in some cases?
Consider the objects: for(i in 1:6){ names<-paste0("var",i) assign(names,runif(30,20,100)) } dataset<-do.call( cbind.data.frame, mget(ls(pattern='*v')) ) cluster<-kmeans(dataset,centers=3)…
-
1
votes2
answers186
viewsA: What is the use of the ".Random.Seed" vector?
I will complement the reply given by @Márcio Mocellin on the second topic: how to eliminate this object? As quoted by @Tomás Barcellos in the comments: rm(list = ls(all.names = TRUE)) ls(all.names =…
-
5
votes2
answers186
viewsQ: What is the use of the ".Random.Seed" vector?
I realized that in the r there is a hidden vector in the globalenv(), called .Random.seed. Even with the globalenv() with no object, .Random.seed is still available when using the function ls with…
-
4
votes1
answer104
viewsQ: Manipulation of columns-list
I have a tibble so-called my, which contains the column-list data library(tidyverse) dataset<-data.frame(matrix(rnorm(6*30,1000,100),ncol=6)) cluster<-kmeans(dataset,centers=3)…
-
4
votes1
answer896
viewsA: How to generate and decompose a Time Series in R?
I’m going to use a data set that I have (data), just to illustrate: data=structure(list(t = structure(c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,…
-
9
votes2
answers300
viewsQ: Difference between "Function Operator" and "Function Factory"
To the chapter 11 of the book Advanced R, the author defines Function Operator as: A Function Operator is a Function that takes one (or more) functions as input and Returns a Function as output.…
-
1
votes1
answer230
viewsQ: How to send outliers with ggplot + geom_boxplot?
I have the gráfico: library(tidyverse) dataset<-as_tibble(matrix(rnorm(6*1000,1500,200),ncol=6)) cluster<-kmeans(dataset,centers=3) dataset$kmeans<-as.factor(cluster[['cluster']])…