Posts by Guilherme Marthe • 550 points
16 posts
-
-1
votes2
answers550
viewsA: How to count sequence numbers in R?
I will try to show you a way to solve this problem without relying on exclusive functions. Here I only use the package dplyr contained in the package tidyverse. Assuming the data is in the format…
-
4
votes1
answer148
viewsA: Compare rows from a column
Huuum, I’ve been on your side. I’d say you have two options: based on an analysis of the terms used, create a function that normalizes them, in the billiard style CASE WHEN of SQL, or if_else of R…
ranswered Guilherme Marthe 550 -
0
votes2
answers97
viewsA: How to run a model for each subset of data of a time series to see
Well, as they usually say in R tutorials, "if you’re using a FOR-loop, you’re doing it wrong". In addition to slowing down the code, you are not using one of the most important factors of the…
ranswered Guilherme Marthe 550 -
4
votes2
answers69
viewsA: How to create function where I need to pass the parameter inside a text block in R
Rui’s solution is correct, but when analyzing the way programming is done using strings (interpolation, etc...) in mature packages in R language, the package that seems to me most used is the glue…
-
2
votes1
answer184
viewsA: Creation of empty csv
If you run your code from in REPL (IDLE, ipython, or python itself) the file will not close and the changes will not be 'flushed' (written) to the file. So just add the line arquivo.close() at the…
-
5
votes1
answer85
viewsA: Code improvement
To deal with "forward" or "back" values of an observation, given the ordering of another variable, the dplyr has the functions arrange to order, and lag and lead to access the previous or later…
-
5
votes1
answer186
viewsA: Schedule automatic updates on R
Yes, it does. In a past job of mine, we built a Dash in Shiny that was basically a while (true) and Sys.sleep(5) that kept updating Dashboard data. It would certainly be necessary to refactor the…
ranswered Guilherme Marthe 550 -
0
votes1
answer118
viewsA: Multiprocessing or Multithreading
First time I will give a hint on this kind of subject. Based on this lecture of this year’s pycon, it seems to me that your problem is more suitable for handling and checking str. As it is an…
-
0
votes1
answer46
viewsA: Open files that will be shared between various functions, inside or outside the functions?
If I had to build this type of program, I would cause the function to receive a file type object, and use a 'context manager' (the with) in the main features of the program to make the code more…
-
2
votes2
answers1479
viewsA: Add factors from a data frame?
To have the sum of a variable relative to the value of another factor variable in a data frame, there are ways. My favorite is using the package dplyr: First construct the following data frame with…
ranswered Guilherme Marthe 550 -
0
votes1
answer755
viewsA: Get common values in multiple columns of a dataframe?
Your example is a little strange, since all the rows are present in all columns, but maybe the following method to count the occurrences will help you. import pandas as pd import numpy as np data =…
-
1
votes1
answer238
viewsA: put a command output in a python3 list
The module of Std lib subprocess can help you. import subprocess comando = "ifconfig|grep docker|cut -c 1-4" res = subprocess.check_output(comando, shell=True) And in case, res gets: print(res)…
python-3.xanswered Guilherme Marthe 550 -
2
votes2
answers726
viewsA: Create sequential counter
Your problem is quiet, and like Marcus said, dplyr can handle it. But I found his solution not too general. The following code counts occurrences of x in each group of y (note that I slightly…
-
2
votes1
answer159
viewsA: Create an exploratory chart type weight~collection by filtering treatments in R
I think of two types of graphics for your situation, but all around different packages than you used, (base R). But keep going like I would, it might help you! First Gero some data that seem to have…
-
0
votes1
answer125
viewsA: R generate time series with initial and final dates for service execution periods
Answering here, since I have no reputation to comment on ^_^. I don’t quite understand what you mean, but, follow here, as I would do to create a data frame with the time series of input, ending,…
-
4
votes1
answer5247
viewsA: Calculate mean, standard deviation and coefficient of variation in historical series in R
I’m writing as an answer, since I have no reputation to comment on ^_^. I don’t understand your question. Do you want to group the df for co_entidade, and pick up the statistics from mat13:mat16,…