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. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.