I’ve got a data.frame with 3 columns. The third column has either numbers or character type “1:5”, “30:20”, “1:10”, etc. I’m trying to split the values which have those characters into two and then divide between them but I’m stuck with this:
datos[,3]=gsub(":", " ", datos[,3])
if (datos[,1]==TRUE)
{
s=datos[,3]
chr.pos <- which(unlist(strsplit(s,NULL)) == " ")
chr.count <- length(chr.pos)
one=as.numeric(substr(s,1,chr.pos-1))
two=as.numeric(substr(s,chr.pos+1,nchar(as.character(s))))
datos[,3]=round(two/one,5)
}
Try this. Note: Added ‘col.names’ to suppress default handling of rownames.