Posts by Márcio Mocellin • 1,443 points
51 posts
-
4
votes2
answers54
viewsQ: Why does creating a list with the same generator only work the first time?
In Python 3.6.8, when I materialize the list, it is shown and erases. This is a bug or so it is? >>> vet_neg ['EH01', 'EH02', 'EH03'] Categories (3, object): ['EH01', 'EH02', 'EH03']…
-
0
votes2
answers45
viewsA: How to create independent dataframes in Python
novo_df = df_original.copy(deep=True) Variable assignment in Python does not always create a new object, just allocate a new "tag" to an already existing object
-
0
votes2
answers45
viewsQ: How to create independent dataframes in Python
I have a problem in python, as I create independent dataframe? What can I think of: >>> PREMISSAS['QTD_ESTOQUE_MEDIO'] 0 628.5 1 20202.5 2 42902.0 3 50036.0 4 8561.5 ... 12646 14356.5 12647…
-
1
votes3
answers415
viewsQ: How do I timeout and replay a command line in Python?
I have a request for information that simply does not receive information and stands still, so forward executed and I have the answer. Then, how to have the command line be canceled after a time…
-
0
votes1
answer171
viewsQ: How to run a virtual python Environment on the linux crontab?
created a virtual Environment: python -m venv test pip install -r requirement.txt And I created a scrip C:\fnord\Documents\Scripts_python\test\Scripts\test.py So, how should I proceed to create…
-
0
votes1
answer466
viewsQ: How to make a sequence dates in python?
I need to create a date array of 2018-01-01, 2020-01-11, the dates being nay can be continuous (eg 2018-01-01, 2018-01-02, 2018-01-03...) and include the ends. The closest I could get was: import…
-
0
votes1
answer593
viewsQ: How do you git pull all branches?
I have several branches and doing two versions of a script, in separate branches on a development server. So how to update all branches, from clone, on production server?
gitasked Márcio Mocellin 1,443 -
-2
votes2
answers225
viewsQ: Logic test inside the Python array
In the R I can have this structure var1 <-TRUE var2 <-FALSE paste0("ANO_544, SEMANA", if(var1 == TRUE){", COD_NEGOCIO"}, if(var2 == TRUE){", CATEGORIA"}, ", MODULADO") And I got an answer:…
-
1
votes0
answers74
viewsQ: How to predict the various statistical models generated in R in Power BI?
I trained several models in the R, like these: iris2 <- data.frame(zzz= sample(c(0, 1),size = length(iris$Sepal.Length), replace = TRUE), iris) for (i in unique(iris$Species)) { saveRDS(glm(zzz ~…
-
3
votes1
answer40
viewsQ: How to reference columns in a R function?
My question is how to announce a column in the Arglist of a Function.Example: I want to do this library(data.table) a<-mtcars data.table::setDT(a) a[,.( disp2 = sum(disp), cyl2 = mean(cyl) ), by…
-
1
votes0
answers46
viewsQ: It’s coming up on Rstudio. Is this a bug?
When do I perform Ctrl+Alt+B to execute the command in the script, occasionally it is inserted in my script ☺, ♥, ♦ and ♣. This is some bad rstudio configuration or a bug in this IDE?…
rstudioasked Márcio Mocellin 1,443 -
4
votes1
answer63
viewsQ: How to perform "sudo" commands between servers?
Before running a R script on server 'A' I have to restart Shiny-server on server 'B'. /bin/ssh cabala@***.***.***.*** 'sudo service shiny-server restart' I would like to enter a command into the R…
-
5
votes1
answer51
viewsQ: How to store the password in the R script in the package 'Encryptr'?
I did it: library(encryptr) genkeys() And I created the password: 0)]30l^8 password<-"0)]30l^8" data(gp) write.csv(gp, "gp.csv") encrypt_file("gp.csv") My problem: How to automatically enter the…
-
1
votes1
answer51
viewsA: Why R is not finding the created function
Why no function has been defined. Read this
-
1
votes2
answers349
viewsA: Import csv - 18 million lines in R
Use the argument colClasses of function read.csv, where the class of each column will be announced. Example: colClasses = c("character", "character", "complex", "factor", "factor", "character",…
-
1
votes0
answers39
viewsQ: How to optimize search parameters in r?
I’ve been waiting for hours for my code to finish running. I imagine there must be a smarter way to do this, after all I don’t need to visit every point when I have a monotonous function around a…
-
2
votes1
answer104
viewsQ: How to read a dataset over http in R?
I have access through a link: 'http://**.**.**.**/matrix/pesquisa_2019-03-17.feather' ou a<-readRDS('http://**.**.**.**/matrix/pesquisa_2019-03-17.rds') But I can’t access them…
-
5
votes1
answer181
viewsQ: How to parallelize on multiple levels in R?
I’ve been researching how to parallelize for in R and found the package foreach, which, from what I understand and correct me if I’m wrong, replaces the for as follows: library(foreach) vetor <-…
-
4
votes2
answers186
viewsA: What is the use of the ".Random.Seed" vector?
.Random.Seed is an integer vector, containing the state of the random number generator (RNG) for the generation of random numbers in R. It can be saved and restored, but should not be changed by the…
ranswered Márcio Mocellin 1,443 -
2
votes2
answers501
viewsQ: How to receive an input during an R function?
It is possible to ask a question and receive an input while executing a function? Example: formateCdoispontos<-function(){ print('Tem certeza que quer fazer isso? (S/N)') ...…
-
3
votes1
answer77
viewsQ: How to change a value in a list of R files?
I have a list of files, example 001.R and 002.R. Usually I do: for (i in c('001.R' e '002.R')){source(i)} However, there is now a parameter within each file that I need to change. No 001.R and 002.R…
-
0
votes1
answer143
viewsA: How to make a linear regression in postgresql?
Yes. The command is regr_intercept(Y, X) returns the intercept, i.e., the value b of the equation Y=aX+b, and the command regr_slope(Y, X) returns the angular coefficient, also called the slope of…
-
5
votes2
answers498
viewsQ: How to make mobile sum in R?
I have a vector 1:50 and need to perform a moving sum (equal to moving average), that is, in the case of the last 5 observations, the new vector would be c(sum(1:5), sum(2:6), sum(3:7), ...,…
-
1
votes2
answers15237
viewsQ: How to remove accent in Python?
In R I would accomplish this way iconv('Arapeí', to="ASCII//TRANSLIT"), so, there’s some simple way to do this in Python?
pythonasked Márcio Mocellin 1,443 -
6
votes2
answers823
viewsQ: What is the difference between [] and [[]] in the R?
I just used the [ ] to define the position of an element in a vector or matrix ([ ], [,], [, ,]...), but how does the [[ ]]?
rasked Márcio Mocellin 1,443 -
0
votes1
answer8005
viewsQ: How to create a python function to connect sql server?
To summarize the connection process, I’m trying to create a function to connect the data bunch, but I’m not able to make the connection as expected: def conectar_com_banco(usuario): if usuario in…
-
6
votes1
answer91
viewsQ: How to solve the 53 categories limit of R randomForest?
In R, using the library randomForest, when executed randomForest() I receive the following error message: Error in randomForest.default(m, y, ...) : Can not handle categorical predictors with more…
-
2
votes1
answer404
viewsQ: How do you return multiple objects in a function of r?
The basic structure of a function in R is: function( arglist ) expr return(value) My question is how to return multiple information. For example: funcao<-function(a,b,c){ if(c==1){d<-a+b}…
-
2
votes1
answer212
viewsQ: How to ignore an error in R?
I created a function inside, however, if at some point an error occurs, it is not important to me and I want it to continue until the end, ignoring the error. valor<-1 Erro<-function(valor){…
-
3
votes1
answer359
viewsQ: What is rank-deficient and how to get around that?
I did a linear regression lm(), where he declared some variables as factor, and I got some Bs as NA as: citySão José NA When I made the prediction, the prediction occurred and I received the…
-
1
votes1
answer143
viewsQ: How to make a linear regression in postgresql?
I wish to make a simple linear regression directly in the database. I noticed that postgresql already has some statistical functions, which seems to me to be for this purpose (regr_slope(Y, X),…
-
0
votes1
answer145
viewsQ: How to convert hexadecimal to binary in a matrix in r?
I have a matrix with hexadecimal number, so: [,1] [,2] [,3] [1,] "FA" "F8" "D0" [2,] "CE" "17" "6A" [3,] "0E" "D6" "22" If I try to convert into binary, with hex2bin(matriz) (biblioteca BMS), is…
-
1
votes2
answers159
viewsQ: How to separate a letter from a Character in SQL?
I have a variable of type Character Varying(17) and I need to separate one of the characters, for example the third letter, and use it to filter.For example: SELECT * FROM fnord WHERE…
-
1
votes1
answer91
viewsQ: How to upload to Google Drive from R
I was watching about the googledrive package from R’s CRAN and I’m not getting it to work, how to get it into my account. My goal is to upgrade a data frame and as CSV, direct to my account.
-
3
votes1
answer474
viewsQ: How to look for a word within a text in R
I need to know if within a certain text there is a specific word, for example fnord. So far I’ve only found: x<-"fnord: Você não tem nivel de acesso a está informação." strsplit(x, "[[:punct:]…
rasked Márcio Mocellin 1,443 -
5
votes1
answer647
viewsQ: How to deal with multiple quotes in R?
My problem is using quotes in a query within a R function. I have to call a list of select * from probes."probes_90_2018-05" For that I do: coelho<-dbConnect("PostgreSQL", fnord)…
-
3
votes1
answer323
viewsQ: What does the function of %% and %any% on the r?
I’ve been reading the R’s documentation and the document Arithmetic{base}, Arithmetic Operators I came across the %% who claims to have the mod function, which I assumed was the modulo function, but…
-
4
votes2
answers114
viewsQ: What do you call the previous month in the R?
I need the R to tell me month before we are, that is, we are in "2018-05" and I need it to give me "2018-04". So far my solution has been: format(Sys.Date()-as.integer(format(Sys.Date(),…
-
3
votes1
answer166
viewsA: How to increase the number of iterations of a function in R?
The maximum amount of interactions is defined by the function glm.control(epsilon = 1e-8, maxit = 25, trace = FALSE), so the maximum number of interactions is defined by default as 25.To change it,…
ranswered Márcio Mocellin 1,443 -
1
votes1
answer166
viewsQ: How to increase the number of iterations of a function in R?
My problem is this, when I do the regression >mod<-glm(y~a+b+c,family=gaussian(link="log"), data = matrix) Warning message: glm.fit: algoritmo não convergiu > summary(mod1) ... Number of…
rasked Márcio Mocellin 1,443 -
1
votes0
answers237
viewsQ: How to perform a GLM of a variable with lognormal distribution in R?
I have the problem to define a "Generalized linear model" with the lognormal distribution. Simply the function glm does not accept this distribution and I saw the suggestion to use the following…
-
3
votes2
answers154
viewsA: Use of if and Else
Your problem is in the use of {}, because I think R is trying to compile everything after the first Else at the same time. To facilitate the construction of the function use ifelse(test, yes, no).In…
ranswered Márcio Mocellin 1,443 -
3
votes2
answers144
viewsA: Create an object that contains four words. Use the sample function to sample 1000 values of that object
Look: pal <- c("oi","ola","hey","hi") > is.factor(c("oi","ola","hey","hi")) [1] FALSE > is.vector(c("oi","ola","hey","hi")) [1] TRUE Thus pal is a vector and not a category vector, so…
-
5
votes2
answers558
viewsQ: How to make concentric circles in r Plot
I need to make concentric circles, preferably displaced from the origin, in function plot() to serve as a visual reference to a function. I tried the abline(), but I was unsuccessful.…
-
5
votes3
answers743
viewsA: Count of TRUE and FALSE
Use the Summary function(), I<-sample (c(0,1), 8, T) V<-I==1 So I created a TRUE FALSE vector > summary(V) Mode FALSE TRUE logical 6 2…
-
4
votes1
answer579
viewsQ: creation of gif in r
I’m trying to create a Plot GIF below: x<-NULL y<-NULL for(i in 1:500){ y[i]<-sum(rnorm(i))/i x[i]<-i plot(y~x, type="l") abline(y=0) Sys.sleep(0.25) }…
-
5
votes2
answers1750
viewsQ: How to create a for in R with the indexes of a data frame
If I have a date.: > dato<-as.data.frame(matrix(1:64,8,8,T))[-3,] > dato V1 V2 V3 V4 V5 V6 V7 V8 1 1 2 3 4 5 6 7 8 2 9 10 11 12 13 14 15 16 4 25 26 27 28 29 30 31 32 5 33 34 35 36 37 38 39…
-
3
votes1
answer211
viewsA: Using the lm function of R to solve the autocorrelation problem
If this is a time series, it’s best to work with https://cran.r-project.org/web/views/TimeSeries.html, but if you really want to do this, then: create a delay column (lag) and p-value lag<-x…
-
3
votes2
answers221
viewsQ: Create a vector with the Levels of a factor in r
I have a column in my data matrix as follows: > as.factor(matriz$especime) [1] 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 [29] 3 3 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7…
-
3
votes1
answer221
viewsA: Values in the chart axes in Rstudio
If you are using the X column, it may be because it has very long values,then it makes a day column 19:29, but by definition the values and title of the axis should appear. Try using the formula,…