[R] replacing rows data.frame

evelyne evelyne.c88 at gmail.com
Fri Oct 19 13:06:04 CEST 2012


I create a data.frame using :
alloc <- data.frame(matrix(nrow=length(unique(mid2agi$gene)), ncol=8))
colnames(alloc) <- c('agi', 'hit_len', 'q_len', 'identity', 'ratio', 'e',
'ok' ,'gene')
alloc$gene <- unique(mid2agi$gene)

this results in: 
> head(alloc)
 agi hit_len q_len identity   ratio          e    ok           gene
NA NA NA NA NA NA NA BrChr1g00001V4
NA NA NA NA NA NA NA BrChr1g00002V4

and I already have a dataframe (mid2agi) containing both integers and
factors.
In my empty dataframe I want to replace rows using:

for (i in (1:nrow(alloc)) ) {
    find <- alloc[i,]$gene
    submid2agi <- subset(mid2agi, gene %in% find)
    max <- which.max(submid2agi$identity * submid2agi$ratio)
    if (length(max) > 0){
       *alloc[i,] <- submid2agi[max,]*
   }
}

But my problem is that all values are now interpreted as integers, so my
text in my factors are converted to numbers.
Can anyone provide me with tips on how to solve this?

ouoput:
agi hit_len q_len identity   ratio          e ok           gene
*18296*     344   551   86.919 0.62432 2.1142e-89  *2* BrChr1g00001V4

SHOULD be:
 agi hit_len q_len identity   ratio          e    ok           gene
AT4G38360.2     344   551   86.919 0.62432 2.1142e-89  True BrChr1g00001V4

Thanks you..
Evelyne


  



--
View this message in context: http://r.789695.n4.nabble.com/replacing-rows-data-frame-tp4646731.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list