Hello,

in my code, I need to convert the columns from a robjects.DataFrame to other 
data types (list, for example). Howver, I've found a problem when dealing with 
data that contains NAs. In particular, I'm referring to non-numeric columns, 
that are represented as FactorVectors.

Example code:

import rpy2.robjects as robjects

data = robjects.DataFrame.from_csvfile("file_with_NAs_in_columns", sep="\t")

column_with_na = data.rx2("Column")

print column_with_na

[1] <NA> <NA> <NA> some_value
Levels: some_value

and If I issue 

print column_with_na[0]

I get:
-2147483648

And of course, accessing the levels I only get some_value. Converting to other 
types of Vector doesn't seem to help.

Notice that this works if I do

base = importr("base")
column_value = base.as_vector(column_with_na)
column_value = list(column_value)
print column_value
['NA', 'NA', 'NA', 'some_value']

Is there a way to translate the column *including* the NAs, into a Python list 
without doing the hackish way described above?

This is with RPy 2.1 alpha 2. I admit that there may be a problem with my 
installation as I'm running a local copy of rpy2 2.1 as I still have a system-
wide 2.0.x needed for some projects.

-- 
Luca Beltrame, Ph.D. 
Post-doctoral research fellow - Duccio Cavalieri group
Department of Pharmacology, University of Firenze

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to