Posts by Julio Trecenti • 987 points
19 posts
-
2
votes1
answer99
viewsA: Data frame handling
See if this code helps. I’m testing with mtcars. You need to install the packages dplyr, tidyr and janitor mtcars # renomeia as colunas para ficar parecido com seu exemplo names(mtcars) <- c("a",…
ranswered Julio Trecenti 987 -
4
votes1
answer306
viewsA: How to plot a curve to separate data?
Attempt to resolve: Step 1: Generate the data # pacotes library(tidyverse) library(mvtnorm) # reprodutibilidade set.seed(10) # observações N <- 1000 # lista de parâmetros parms <- list( a =…
-
3
votes1
answer505
viewsA: Create a sequence of useful days in R
Use the package bizdays of Wilson Freitas # install.packages('bizdays') bizdays::bizseq('2017-01-01', '2017-01-31', cal = "Brazil/ANBIMA") #> [1] "2017-01-02" "2017-01-03" "2017-01-04"…
-
3
votes1
answer50
viewsA: Adjust function with Laplacesdemon
David, I think there’s a little concept problem in your code. The way you wrote it, you’re treating nu as a probability density function, but the random variable is the y! You can use to notice that…
-
2
votes1
answer178
viewsA: POST function of the httr package returns NA
Rumenick, is an encoding problem. The httr tries to turn the output into UTF-8 and when it does, leaves NA. The solution is to manually insert the encoding, which in case is 'latin1': req <-…
-
2
votes1
answer53
viewsA: Dots (...) with variable name
I managed to solve using do.call and a named list. do.call(f, setNames(list(1), x)) does the work.
ranswered Julio Trecenti 987 -
3
votes1
answer53
viewsQ: Dots (...) with variable name
I need to run a function like f <- function(...) { l <- list(...) l[["hortela"]] } x <- 'hortela' If we do f(hortela = 1) we have the result 1, what is expected. What do I call it f() using…
rasked Julio Trecenti 987 -
4
votes4
answers1920
viewsA: Create column with sum and percentage of the maximum of other columns
Less verbiage response (not need to write the name of all columns), but with more code library(tibble) library(dplyr) library(tidyr) d %>% # adiciona um "id" com os nomes das linhas…
ranswered Julio Trecenti 987 -
3
votes1
answer634
viewsA: Multiple imputation with dashboard data in R
I tried to replicate the problem by running it here library(dplyr) library(Amelia) set.seed(123) ufs <- c("AC", "AL", "AM", "AP", "BA", "CE", "DF", "ES", "GO", "MA", "MG", "MS", "MT", "PA", "PB",…
ranswered Julio Trecenti 987 -
10
votes3
answers2014
viewsA: Web scraping with R
My access was blocked while I was doing, but my code ended up being below. There are some explanations of how each part works. I only used contemporary Hadley Wickham packages, including the rvest…
-
6
votes2
answers202
viewsQ: data.frame hierarchy for nested list in R
I got the following data.frame d: x <- data.frame(a=letters[1:3], b=letters[4:6], c=letters[7:9], stringsAsFactors=F) d <- tidyr::expand(x) d Source: local data frame [27 x 3] a b c 1 a d g 2…
rasked Julio Trecenti 987 -
2
votes1
answer255
viewsA: Differences between Rcurl, httr (R) and requests (python) when making a POST
Interestingly, I was able to solve the problem by simplifying the code of httr. It seems that the package has received an update and now receives a parameter encode, that can receive multipart…
-
4
votes1
answer255
viewsQ: Differences between Rcurl, httr (R) and requests (python) when making a POST
I was wanting to access a page that gets you by clicking "Displays all the above documents" at that link. The company I took is just an example, I have no interest in it. I tried to resolve this…
-
4
votes1
answer330
viewsQ: Classify a text array using regular expressions using R
Let’s say I have the following array of texts (character): d <- data.frame(id=1:3, txt=c('Um gato e um cachorro', 'Cachorros jogam bola usando alpargatas', 'gatinhos cospem bolas de pêlos'),…
-
2
votes1
answer206
viewsA: Order of operations in the R
I will rewrite part of my comments as an answer to the question How the order of operations in R works? @Danielfalbel, what you said has to do with the concept of "precedence" and is defined in…
ranswered Julio Trecenti 987 -
13
votes4
answers1143
viewsQ: Add rownames as column using dplyr
I would like to do something that is quite simple using the common R syntax, but using the package dplyr. The task is basically to add the row.names of an object data.frame as column on that same…
-
5
votes3
answers3977
viewsA: Organize data in Excel to open as table in R?
From the result you have observed, I will assume you are using a Portuguese version of Windows Excel. Usually, when we save a Windows Excel spreadsheet in CSV, it is saved with ; as a separator.…
-
7
votes1
answer480
viewsA: Is there a way to open a direct SQL table in a data.table, without doing the SQL path > data.frame > data.table?
Sniffing around the code descrobri that the secret is in the function fetch, which is an implementation made in the package RSQLite, for objects of the type SQLiteResult (class S4), which implements…
-
2
votes2
answers1789
viewsA: A: What objects does the Names() attribute apply to?
Your question is related to data structures. Look at Hadley’s book: http://adv-r.had.co.nz/Data-structures.html names is an attribute type (which are the metadata in R), which serves to name…
ranswered Julio Trecenti 987