Question

I want to do the equivalent of this R script:

> csvData <- read.csv(file='/homes/ndeklein/test.csv', head=TRUE, sep='\t')
> csv = subset(csvData, !duplicated(id))

in rpy2. However, if I import rpy2.robjects as R, it does not recognize R.r['!duplicated'] (like this):

import rpy2.robjects as R
csvData = R.r['read.csv'](file='/homes/ndeklein/test.csv', head=True, sep='\t')
csv = R.r['subset'](csvData, R.r['!duplicated']('id'))

How can I use !duplicated in rpy2?


edit:

R.r['duplicated']

does work, so I'm looking for how to make ! work in rpy2

Was it helpful?

Solution

I got the answer trough a mailing list, in case someone else needs it:

Using R.r'!' instead of R.r'!duplicated' works.

# getting the not sign of R
rnot = R.r['!']
# getting duplicated
duplicated = R.r['duplicated']
# get only the rows with unique ids and put it in a new matrix
csvUniqID = R.r['subset'](csvData,  rnot(duplicated(csvData[0])))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top