Вопрос

In R, I can do

> df <- read.csv("file.csv")
> sapply(df, class)
  patient      time    censor WHO.Grade       Age       Sex 
 "factor" "numeric" "integer"  "factor"  "factor"  "factor"

How can I get the equivalent output from rpy2?

I have tried a number of things, but what I really want is to fill in the blank:

>>> df = DataFrame.from_csvfile("file.csv")
>>> r.sapply(df, _____)

This doesn't give the output I want,

>>> df.rclass
<rpy2.rinterface.SexpVector - Python:0x100b2bd98 / R:0x7fbb0bed62d8>

Nor does:

>>> df.rx2("time").rclass
<rpy2.rinterface.SexpVector - Python:0x100b2ba68 / R:0x7fbb0bed42a8>
Это было полезно?

Решение

Try:

colclasses = [tuple(x.rclass) for x in df]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top