Re: [R] Convert list with missing values to dataFrame

2013-08-13 Thread arun
quot;a" "1,2,3" "b" "4,5,6" # $ Col2: chr  "1" "2" "3" "4"  str(data.frame(sID,Col2=1:4,stringsAsFactors=FALSE)) #'data.frame':    4 obs. of  2 variables: # $ sID : chr  "a" "1,2,3" "b" "4,5,6

Re: [R] Convert list with missing values to dataFrame

2013-08-13 Thread MacQueen, Don
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))

[R] Convert list with missing values to dataFrame

2013-08-13 Thread Steven Ranney
I have a dataFrame sID <- c("a", "1,2,3", "b", "4,5,6") rID <- c("shr1125", "bwr331", "bwr330", "vjhr1022") tmp <- data.frame(cbind(sID,rID)) but I need to split tmp$sID into three different columns, filling locations where tmp$sID has only one value with NA. I can split tmp$sID by the comma t