Hi,
You could try:
tmp[,1]<- as.character(tmp[,1])
tmp[,1][-grep(",",tmp[,1])]<-paste0(",,",tmp[,1][-grep(",",tmp[,1])])
tmp2<-data.frame(read.table(text=tmp[,1],sep=",",header=FALSE,stringsAsFactors=FALSE),rID=tmp[,2],stringsAsFactors=FALSE)
colnames(tmp2)[1:3]<-paste("sID",letters[1:3],sep="
Try,
sID <- c("a", "1,2,3", "b", "4,5,6")
tmp1 <- strsplit(sID,',')
tmp2 <- lapply(tmp1,
function(x) if (length(x)==1) c('','',x) else x )
tmp3 <- matrix(unlist(tmp2),ncol=3, byrow=TRUE)
rID <- c("shr1125", "bwr331", "bwr330", "vjhr1022")
newdf <- data.frame(cbind(tmp3,rID))
2 matches
Mail list logo