I am using R on a MacBook. I have an Rmarkdown document and I’m trying to use reticulate in order to use python within R. First I download the libraries: Next I look at an R chunk and figure out my working directory. Then I write mtcars to my desktop. Then I try to use python instead to read in
Tag: r
np.linalg.multi_dot for R
I’m trying to do a nested dot result is effectively x.dot(M.dot(M)): In python this loop can be reduced by: Is there something similar for R? Answer As @akrun commented, you could also use Reduce:
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 th…
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 th…
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 t…
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 …
Summing up all repeated values in a dataset
I have a dataset in which in a column I have the name of a person and in another column I have the amount she was paid for a given service. I’d like to build a list with the names of all people ordained by the total amount they were paid regardless of the service they performed. Example: I figured
making list index possible for python class list
Python has no function for list index argument in __getitem()__, __setitem()__, __delitem()__. Since I have been an R user for long time, it looks quite natural to utilize list index. I know there is pandas or numpy but it is cumbersome to change the type. AND IT NEEDS IMPORTING EXTRA PACKAGE! Here is my prop…
How to invoke a specific shell with python?
I want to invoke a specific command shell in python to execute some scripts. For exemple, in R, I use: system2(os_shell = “C:/Program Files (x86)/pgAdmin III/1.18/pg_dump.exe”, args = “very long argument”) Thanks to this code, I can backup my Postgresql’s tables with a for loop. …