r

Create an R or Python function to generate sets based on the value of C

Create an R or Python function to generate sets based on the value of C Question: I need help creating an R or Python function that generates sets based on the value of C. Here’s an example to illustrate what I’m looking for: For C = 2, I have 2^2 sets, including the sets: Cl_atypique, …

Total answers: 3

Remove palindromic rows based on two columns

Remove palindromic rows based on two columns Question: I have the following data frame: Data_Frame <- data.frame ( A = c("a", "c", "b", "e", "g", "d", "f", "h"), B = c("b", "d", "a", "f", "h", "c", "e", "g"), value = c("0.3", "0.2", "0.1", "0.1", "0.5", "0.7", "0.8", "0.1") effect = c("123", "345", "123", "444", "123", …

Total answers: 1

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: 2

How can I code Vuong's statistical test in Python?

How can I code Vuong's statistical test in Python? Question: I need to implement Vuong’s test for non-nested models. Specifically, I have logistic-regression models that I would like to compare. I have found implementations in R and STATA online, but unfortunately I work in Python and am not familiar with those frameworks/languages. Also unfortunate is …

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