I have a data frame that looks something like this:
dataDemo <- data.frame(POS = 1:4 , REF = c("A" , "T" , "G" , "C") ,
ind1 = c("A" , "." , "G" , "C") , ind2 = c("A" , "C" , "C" , "."),
stringsAsFactors=FALSE)
dataDemo
POS REF ind1 ind2
1 1 A A A
2 2 T . C
3 3 G G C
4 4 C C .
and I would like to replace everything. "" s value REFfor this string. Here is how I did it:
for(i in seq_along(dataDemo$REF)){
dataDemo[i , ][dataDemo[i , ] == '.'] <- dataDemo$REF[i]
}
I would like to know if there is a more โcorrectโ or idiomatic way to do this in R. Usually I try to use * when possible, and it looks like it is easy to adapt to this approach and make it more readable (and works faster ), but despite the fact that he has a lot of time, I have not achieved much success.
source
share