I have a large data.frame where the first three columns contain information about a marker. The remaining columns are of numeric type for that
I think it is better here to put your data in the long format. Here a solution based on reshape2 package , maybe similar to second @Arun solution but syntactically different
library(reshape2)
dat.m <- melt(dat,id.vars=1:3)
dat.m$variable <- gsub('[.].*','',dat.m$variable)
dcast(dat.m,...~variable,fun.aggregate=function(x){
res <- NA_real_
if(length(x) > 0 && max(x)> 0.8)
res <- max(x)
res
})
marker alleleA alleleB X345 X346 X818
1 chr3_21902130_21902131_A_T A T NA 0.8626 0.8626
2 chr3_21902134_21902135_T_C T C NA NA NA
3 kgp5209280_chr3_21902067 T A 1 1.0000 1.0000