In rpy2 what is the equivalent of say:
dataf <- data.frame(a=c(1,2,3), b=c(4,5,6))
dataf$a <- dataf$a + 1
Since dataframe.rx2
is the rpy2 equivalent of [[.dataframe
I would have thought that the answer would have been:
d = {'a': robjects.IntVector((1,2,3)), 'b': robjects.IntVector((4,5,6))}
dataf = robjects.DataFrame(d)
dataf.rx2["a"] = dataf.rx2("a").ro + 1
but that gives the following error:
RRuntimeError: Error in `[[<-.data.frame`(list(a = 1:3, b = 4:6), "a", 2:4) :
argument "value" is missing, with no default
I also tried:
dataf.rx["a"] = dataf.rx("a").ro + 1
dataf[dataf.index("a")] = dataf.rx2("a").ro + 1
without any luck
This should work: