I have a data frame M
. I would like to extract the first part of each string separated by ":"
. I used strsplit
but the result is a large character not a data frame. Could someone please help with this?
M <- read.table(text=
"1/1:205,54,0:18:0:57 1/1:141,39,0:13:0:42 0/0:0,54,255:18:0:45 1/1:174,48,0:16:0:51 0/0:0,84,255:28:0:75
0/0:0,78,255:26:0:99 0/0:0,63,255:21:0:86 0/0:0,45,255:15:0:68 0/0:0,48,255:16:0:71 0/0:0,132,255:44:0:99
0/0:0,78,255:26:0:89 0/0:0,78,255:26:0:89 0/0:0,36,255:12:0:47 0/0:0,33,255:11:0:44 0/0:0,108,255:36:0:99
0/0:0,75,255:25:0:99 0/0:0,54,255:18:0:78 0/0:0,69,255:23:0:93 0/0:0,33,255:11:0:57 0/0:0,96,255:32:0:99
0/0:0,60,75:21:0:74 0/0:0,51,84:17:0:65 0/0:0,48,64:17:0:62 0/0:0,42,65:15:0:56 0/0:0,84,99:28:0:98 ",
head=F, stringsAsFactors=F)
S <- sapply(strsplit(M, ":"), "[", 1)