Skip to content
Advertisement

# Tag: r

## Sort by custom function in R

In python, I can do something like It gives me [1, 5, 99, 100, -5, -7, -100] It is sorted by positive/negative number and abs value. How can I do the same thing in R? Without splitting into positive and negative numbers? a = c(1,100,5,-5,-7,99,-100) Answer Use the order() function: Created on 2022-03-22 by the reprex package (v2.0.1) Another possibility

## How to write a csv file via pandas and read it in R at regular intervals?

Background A driving simulator PC in my lab generates data that I receive via python socket. The data is generated every 1/60th of a second. I continuously save it to a csv file called position.csv. I also want to read position.csv in R to use in a shiny app. I read it every 0.2 seconds. Problem When I run the

## Is there any way to call base python function in r using reticulate?

I got a “generator object” from a python function. However, I tried many ways but failed to read the “generator object” in r using reticulate. I know python base function list() can convert “generator object” to “json”, which I can then read in r. I wonder how to use base python function in r? (I would not prefer to use

## Why is this task faster in Python than Julia?

I ran the following code in RStudio: It reads a huge NASA CSV file, converts it to a dataframe, converts each element to string, and adds them to a vector. RStudio took 4 min and 15 seconds. So I decided to implement the same code in Julia. I ran the following in VS Code: The result was good. The Julia

## Creating a series of Quarters

Let say I have a date Now starting from mydate, I want to create an array of 10 quarters e.g. 2020-Q1, 2020-Q2, … [total 10 values] Is there any direct way to achieve this? In R, this is pretty straightforward, as I can use seq() function to generate the same. Any pointer will be very helpful Answer it doesnt give

## Passing arguments to a R script from a JuPyter notebook on a Mac and vice versa?

I have a JuPyter notebook (in Python), and looking to pass a list of arguments into a R program (stored separately in the same directory). After the R program is executed, it will then pass the …

## Create a matrix of pairwise comparisons between columns

I would like to create a matrix showing the number of row-wise differences for each pairwise comparison of columns. This is what I’m starting with: Ind1 Ind2 Ind3 Att1 A A B Att2 A …

## How to adjust the numerical precision for integers

I’m trying to work with big numbers in R, in my opinion they aren’t even that big. I asked R to return me the module of the division of 6001532020609003100 by 97, I got answer 1; when doing the same calculation in Python I got answer 66. Can someone tell me what’s going on? Answer R doesn’t have the same

## Recode multiple values in several columns in Python [similar to R]

I am trying to translate my R script to python. I have a survey data with several date of birth and education level columns for each family member(from family member 1 to member 10): here a sample: …

## Weibull: R vs Python – slightly different results

I’m trying to replicate R’s fitdist() results (reference, cannot modify R code) in Python using scipy.stats. The results are quite close but still different (difference is at not acceptable level). …

Advertisement