Posts by José • 576 points
16 posts
-
0
votes3
answers152
viewsA: Aggregate string in R
The purrrlyr package makes @Rui’s excellent solution simpler: library(dplyr) library(purrrlyr) library(zoo) dados %>% group_by(cidade) %>% dmap(na.locf) %>% distinct(cidade,.keep_all=T)…
-
3
votes2
answers396
viewsA: Why are loops slow in R? How to avoid them?
Complementing @Marcos Nunes' reply, which is excellent, the text that made me understand the difference between loop and vectorization was this one: Vectorization in R: Why? R is a high-level…
-
1
votes3
answers243
viewsA: How to filter data according to part of the characters of a variable?
Using the df created by @Marcos, you can also work with tidyverse, without the difficulty presented by @Rui: library(tidyverse) library(stringr) dados <- tibble(Nome=c("João Silva", "Pedro…
-
1
votes2
answers63
viewsA: Not Available (how to put information in this position)
Hello @Bianca, try the coalesce function of the dplyr package. It replaces all Nas with the given value, in the example below is zero: x <- sample(c(1:5, NA, NA, NA)) dplyr::coalesce(x, 0L)…
-
4
votes1
answer230
viewsQ: Scrape of MTE mediating system
I’m trying to make the Scrape of the Ministry of Labor mediating system. Basically, I want the relationship of collective agreements and conventions:…
-
5
votes2
answers604
viewsA: PDF to text organizing columns
See if this helps: doc1<-unlist(stringr::str_split(doc,"\\s{5,}|\n")) c1<-paste0(doc1[seq(5,length(doc1),3)],collapse = " ") c2<-paste0(doc1[seq(6,length(doc1),3)],collapse = " ")…
-
2
votes1
answer322
viewsA: How to mount a data.frame with identical elements from another two data frames.
I’m not sure if that’s what you want, but I thought the following scenario: df1<-data.frame(a=1:20) # Data frame com apenas 20 elementos df2<-data.frame(b=11:50) # Data frame com 40 elementos…
-
4
votes2
answers186
viewsA: How can I transform a variable(0-10) into 3 categories?
Another option is to use the function cut. Using the data.frame created by @Daniel: dados <- data.frame(GLEASON = sample(0:10, 50, replace = TRUE)) dados$categorias <- cut(dados$GLEASON,…
-
1
votes1
answer120
viewsA: How to exclude variable E observations in a matrix in R?
See if that’s what you want: matriz<- matrix(1:3794,ncol=14) # Cria uma matriz qualquer 271x14 matriz[sample(1:length(matriz),50,replace=FALSE)]<-NA # Substitui 50 valores por NA…
-
4
votes1
answer215
views -
2
votes3
answers955
viewsA: How to place multiple formats on the dots of my PCA by ggplot2
The Factominer package in combination with the factoextra package were designed to address this situation. Note that quali.sup, in the PCA function, and habillage, in the fviz_pca_ind function, are…
-
3
votes2
answers91
viewsA: Adding the same substring to multiple columns in R
Try this: df<-data.frame(var1=c("a","b","c"),var2=c("g","r","v"),stringsAsFactors=F) df[]<-paste0(unlist(df[]),"PF")
-
2
votes1
answer122
viewsA: https (webservice) requisition from the São Paulo Public Treasury
I ended up partially solving (works only from 2010) the issue with the function curlPerfom() package RCurl. I took the example from here. From that, I got the information on the header and the body…
-
4
votes1
answer122
viewsQ: https (webservice) requisition from the São Paulo Public Treasury
I’m trying to make a request https the Webservice of the São Paulo Public Treasury, but I don’t know where I’m going wrong. This is the address: http://www.fazenda.sp.gov.br/contas/webservice.shtm…
-
4
votes4
answers5814
viewsA: How to read microdata from ENEM in R?
A very good solution is to use the read_csv_chunked() function of the readr package. This function allows the reading and application of a function to each Chunk (number of lines) iteratively.…
-
3
votes1
answer634
viewsQ: Multiple imputation with dashboard data in R
I have panel data in the following format: estado ano var1 var2 var3 It turns out that variable 2 (var2) has no data corresponding to one of the years. I tried to perform multiple imputation with…