[R] Row name of empty string issue

adiamond adiamond at csidentity.com
Fri Aug 10 20:12:47 CEST 2007


I have a data.frame with rownames taken from a database.  Unfortunately, one
of the rownames (automatically obtained from the DB) is an empty string.  I
often do computations on the DB s.t. the answers (rows) are indexed with
respect to the rownames so a computation on a DB record might necessitate
the indexing into the data.frame by the emtpy row name.  Unfortunately, that
doesn't seem to work.  Explicitly:
I have this statement (in a loop going through sourceNames which are
rownames of the data.frames CurrentRecordBlankFieldsCountSums and 
BlankFieldsCount):

BlankFieldsCount[sourceNamei,]= BlankFieldsCount[sourceNamei,] + 
CurrentRecordBlankFieldsCountSums[sourceNamei ,];

if sourceNamei is any name other than "" it works fine but otherwise
CurrentRecordBlankFieldsCountSums[sourceNamei ,] returns a bunch of NAs
because apparently it didn't fine a row named "".  IMHO, if R lets you name
a row "", then it should let you index it with the name "".

Anyway, as further proof of the setup:
> rownames(CurrentRecordBlankFieldsCountSums)[1]
[1] ""
# So the first rowname of CurrentRecordBlankFieldsCountSums is an empty
string ""

> CurrentRecordBlankFieldsCountSums[1 ,]
 IDCaseNumber Category SSN LastName FirstName
            0        0   1        0         0
# So, the first row has some data (not just NAs as would be returned if that
row didn't exist)

But ff I index that same row using the rowname it doesn't find the row:
> CurrentRecordBlankFieldsCountSums[rownames(
> CurrentRecordBlankFieldsCountSums)[1] ,]
   IDCaseNumber Category SSN LastName
NA           NA       NA  NA 
# I get the same result if I do this:CurrentRecordBlankFieldsCountSums["" ,]

As a sanity check:
> "" == rownames(CurrentRecordBlankFieldsCountSums)[1]
[1] TRUE

For other rows, (rownames that aren't "", there's no problem):
> rownames(CurrentRecordBlankFieldsCountSums)[2]
[1] "FRED"
> CurrentRecordBlankFieldsCountSums[rownames(
> CurrentRecordBlankFieldsCountSums)[2] ,]
                      IDCaseNumber Category SSN LastName FirstName
FRED            0        0   0        0 

-- 
View this message in context: http://www.nabble.com/Row-name-of-empty-string-issue-tf4250291.html#a12096455
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list