r

pyreadr not working (how to import RData file to python)

pyreadr not working (how to import RData file to python) Question: I always get an empty dictionary when I import any RData file into Python using pyreadr. Here is my Python code: import pyreadr result = pyreadr.read_r(‘data.RData’) print(result.keys()) which returns odict_keys([]) I have pyreadr installed and am running Python version 3.7.11 on Mac. In the …

Total answers: 1

Forming a symmetric matrix counting instances of being in same cluster

Forming a symmetric matrix counting instances of being in same cluster Question: I have a database that comprises cities divided into clusters for each year. In other words, I applied a community detection algorithm for different databases containing cities in different years base on modularity. The final database (a mock example) looks like this: v1 …

Total answers: 2

Compute share of resources used by node i w.r.t. neighbors on a large network

Compute share of resources used by node i w.r.t. neighbors on a large network Question: Purpose The main purpose is to be able to compute the share of resources used by node i in relation to its neighbors: r_i / sum_j^i{r_j} where r_i are node i resources and sum_j^i{r_j} is the sum of i’s neighbors’ …

Total answers: 1

Split string column to multiple columns in R/Python

Split string column to multiple columns in R/Python Question: I’m trying to split the following string str = "A (B) C, D (E) F, G, H, a (b) c" into 9 separate strings like: A, B, C, D, E, {F, G, H}, a, b, c I’ve tried str = "A (B) C, D (E) F, …

Total answers: 1

NA_character_ not identidied as NaN after importing it into Python with rpy2

NA_character_ not identidied as NaN after importing it into Python with rpy2 Question: I am using the following code inside a R magic cell: %%R -o df library(tibble) df <- tibble(x = c("a", "b", NA)) However, when I run in another cell (a Python one): df.isna() I get x 1 False 2 False 3 False …

Total answers: 1

How to create polygon from bbox data in python?

How to create polygon from bbox data in python? Question: I have created a code in R which extracts bbox from a list of points and then creates a polygon using st_as_sfc. Now I am trying to do the same in python where I was able to get the bbox coordinates from the list of …

Total answers: 2

Facing issues when running a shiny app for Python locally

Facing issues when running a shiny app for Python locally Question: I want to run shiny app for python locally. The following code works like a charm: cd/d D:/app1 py from shiny import run_app run_app() However, when I try the following code, it does not work. cd/d D: py from shiny import run_app run_app("app1:app") Any …

Total answers: 1

pythonic equivalent of R double pivot and filter

pythonic equivalent of R double pivot and filter Question: A task I come up against reasonable often is something like the following transformation: from: home_team_id away_team_id home_team away_team 1 1 2 Arsenal Tottenham 2 2 3 Tottenham Chelsea to team value 1 Arsenal 1 2 Tottenham 2 3 Tottenham 2 4 Chelsea 3 in my …

Total answers: 1

What is the equivalent of .loc with multiple conditions in R?

What is the equivalent of .loc with multiple conditions in R? Question: I wonder if there is any equivalent of .loc in R where I am able to have multiple condition that would work in a for loop. In python I accomplished this using .loc as seen in the code below. However, I am unable …

Total answers: 1

How to order a nested list in R

How to order a nested list in R Question: I need the code to be in R Exemple I have a list: [[0,’A’,50.1], [1,’B’,50.0], [2,’C’,50.2], [3,’D’,50.7], [4,’E’,50.3]] I want to order it based on the 3rd elemnts only so I get a result like this [[1,’B’,50.0], [0,’A’,50.1], [2,’C’,50.2], [4,’E’,50.3], [3,’D’,50.7]] and then reorder the index …

Total answers: 1