[R] Odp: splitting the column

Petr PIKAL petr.pikal at precheza.cz
Tue Jan 8 16:08:05 CET 2008


Hi

Do you have a source data available. Maybe you could try to read it in 
such manner that you will get desired result without further adjustment. 
See all options in read.* functions. 

If you really wanted to split already imported data you will need to use 
regular expressions and I am not an expert in them so I cannot help you 
much. Maybe you can paste all items in one row together and then strsplit 
the vector and bind all rows together.
e.g.

strsplit(paste("a b    10", "c   d   15000", sep=" "), " +")

Regards

Petr
petr.pikal at precheza.cz

r-help-bounces at r-project.org napsal dne 08.01.2008 15:36:30:

> Hi,
> 
>   I have a matrix data with 21 rows and 6 columns. Below and attach with 
is my
> matrix data. My problem is to split the column into 3 subcolumns (except 
for 
> column 3 and 4) . I want my new matrix data to have 14 columns and 21 
rows. 
> Kindly help is highly appreciated.
> 
>       [,1]           [,2]                         [,3]       [,4] [,5]   
 
> [,6] 
>  [1,] "CS 1 73 "     " cfa1 3251712 24126920 "    "20875208" "3"  " 
hsa18 
> 132170848 50139168 "  " 24126920 24153560 8 " 
>  [2,] "CS 2 3 "      " cfa1 24153560 24265894 "   "112334"   "27" " 
hsa18 
> 50105060 49934572 "   " 24265894 24823786 7 " 
>  [3,] "CSO 3.1 6 "   " cfa1 24823786 27113036 "   "2289250"  "3"  " 
hsa18 
> 48121156 46579500  "  " 27113036 27418228 13" 
>  [4,] "CSO 3.2 4 "   " cfa1 27418228 27578150 "   "159922"   "25" " 
hsa18 
> 13872043 13208795  "  " 27578150 28055666 9 " 
>  [5,] "CS 4 4 "      " cfa1 28055666 28835230 "   "779564"   "5"  " hsa6 

> 132311008 133132200 "  " 28835230 29482792 7 " 
>  [6,] "CS 5 46 "     " cfa1 29482792 40120672 "   "10637880" "4"  " hsa6 

> 133604208 146227152 "  " 40120672 40539680 8 " 
>  [7,] "CS 6 9 "      " cfa1 40539680 43339444 "   "2799764"  "3"  " hsa6 

> 146390608 149867328 "  " 43339444 43390788 13 " 
>  [8,] "CSO 7.1 74 "  " cfa1 43390788 59714992 "   "16324204" "5"  " hsa6 

> 149929104 169714432  " " 59714992 59864308 15" 
>  [9,] "CSO 7.2 52 "  " cfa1 59864308 72417520 "   "12553212" "4"  " hsa6 

> 116707976 131508152  " " 72417520 73256040 7 " 
> [10,] "CSO 8.1 12 "  " cfa1 73256040 75192808 "   "1936768"  "6"  " hsa9 

> 98441680 96360824  "   " 75192808 75272528 6" 
> [11,] "CSO 8.2 56 "  " cfa1 75272528 91881664 "   "16609136" "3"  " hsa9 

> 89530256 70341312  "   " 91881664 92281272 5" 
> [12,] "CSO 8.3 22 "  " cfa1 92281272 96913624 "   "4632352"  "5"  " hsa9 

> 261625 5755076  "      " 96913624 98067040 5" 
> [13,] "CSO 8.4 15 "  " cfa1 98067040 100692560 "  "2625520"  "6"  " hsa9 

> 93833248 89771184  "   " 100692560 101013264 13" 
> [14,] "CSO 8.5 18 "  " cfa1 101013264 102120080 " "1106816"  "16" " hsa9 

> 95832896 94012312  "   " 102271920 102458192 25 "
> [15,] "CS 9 55 "     " cfa1 102458192 105936824 " "3478632"  "16" " 
hsa19 
> 63765096 59618416 "   " 105936824 106097392 35 "
> [16,] "CSO 10.1 81 " " cfa1 106097392 110263696 " "4166304"  "19" " 
hsa19 
> 59386008 54256216  "  " 110263696 110288752 60" 
> [17,] "CSO 10.2 18 " " cfa1 110288752 110567608 " "278856"   "65" " 
hsa19 
> 54163196 53814360  "  " 110567608 110575576 50" 
> [18,] "CSO 10.3 60 " " cfa1 110575576 112727048 " "2151472"  "28" " 
hsa19 
> 53649284 50959884  "  " 112727048 112775144 40 "
> [19,] "CS 11 173 "   " cfa1 112775144 119848336 " "7073192"  "24" " 
hsa19 
> 50887772 40849556 "   " 119848336 119880560 55 "
> [20,] "CS 12 33 "    " cfa1 119880560 121690672 " "1810112"  "18" " 
hsa19 
> 40824500 38556448 "   " 121690672 121820640 16 "
> [21,] "CS 13 22 "    " cfa1 121820640 124798800 " "2978160"  "7"  " 
hsa19 
> 38391408 34709332 "   " 124798800 NA NA " 
> 
> 
>   Thanks in advance.
> 
>   Cheers,
>   Anisah
> 
> 
> ---------------------------------
>        [,1]           [,2]                         [,3]     [,4]    [,5] 
 
> [,6] 
>  [1,] "CS 1 73 "     " cfa1 3251712 24126920 "    "20875208" "3"  " 
hsa18 
> 132170848 50139168 "  " 24126920 24153560 8 " 
>  [2,] "CS 2 3 "      " cfa1 24153560 24265894 "   "112334"   "27" " 
hsa18 
> 50105060 49934572 "   " 24265894 24823786 7 " 
>  [3,] "CSO 3.1 6 "   " cfa1 24823786 27113036 "   "2289250"  "3"  " 
hsa18 
> 48121156 46579500  "  " 27113036 27418228 13" 
>  [4,] "CSO 3.2 4 "   " cfa1 27418228 27578150 "   "159922"   "25" " 
hsa18 
> 13872043 13208795  "  " 27578150 28055666 9 " 
>  [5,] "CS 4 4 "      " cfa1 28055666 28835230 "   "779564"   "5"  " hsa6 

> 132311008 133132200 "  " 28835230 29482792 7 " 
>  [6,] "CS 5 46 "     " cfa1 29482792 40120672 "   "10637880" "4"  " hsa6 

> 133604208 146227152 "  " 40120672 40539680 8 " 
>  [7,] "CS 6 9 "      " cfa1 40539680 43339444 "   "2799764"  "3"  " hsa6 

> 146390608 149867328 "  " 43339444 43390788 13 " 
>  [8,] "CSO 7.1 74 "  " cfa1 43390788 59714992 "   "16324204" "5"  " hsa6 

> 149929104 169714432  " " 59714992 59864308 15" 
>  [9,] "CSO 7.2 52 "  " cfa1 59864308 72417520 "   "12553212" "4"  " hsa6 

> 116707976 131508152  " " 72417520 73256040 7 " 
> [10,] "CSO 8.1 12 "  " cfa1 73256040 75192808 "   "1936768"  "6"  " hsa9 

> 98441680 96360824  "   " 75192808 75272528 6" 
> [11,] "CSO 8.2 56 "  " cfa1 75272528 91881664 "   "16609136" "3"  " hsa9 

> 89530256 70341312  "   " 91881664 92281272 5" 
> [12,] "CSO 8.3 22 "  " cfa1 92281272 96913624 "   "4632352"  "5"  " hsa9 

> 261625 5755076  "      " 96913624 98067040 5" 
> [13,] "CSO 8.4 15 "  " cfa1 98067040 100692560 "  "2625520"  "6"  " hsa9 

> 93833248 89771184  "   " 100692560 101013264 13" 
> [14,] "CSO 8.5 18 "  " cfa1 101013264 102120080 " "1106816"  "16" " hsa9 

> 95832896 94012312  "   " 102271920 102458192 25 "
> [15,] "CS 9 55 "     " cfa1 102458192 105936824 " "3478632"  "16" " 
hsa19 
> 63765096 59618416 "   " 105936824 106097392 35 "
> [16,] "CSO 10.1 81 " " cfa1 106097392 110263696 " "4166304"  "19" " 
hsa19 
> 59386008 54256216  "  " 110263696 110288752 60" 
> [17,] "CSO 10.2 18 " " cfa1 110288752 110567608 " "278856"   "65" " 
hsa19 
> 54163196 53814360  "  " 110567608 110575576 50" 
> [18,] "CSO 10.3 60 " " cfa1 110575576 112727048 " "2151472"  "28" " 
hsa19 
> 53649284 50959884  "  " 112727048 112775144 40 "
> [19,] "CS 11 173 "   " cfa1 112775144 119848336 " "7073192"  "24" " 
hsa19 
> 50887772 40849556 "   " 119848336 119880560 55 "
> [20,] "CS 12 33 "    " cfa1 119880560 121690672 " "1810112"  "18" " 
hsa19 
> 40824500 38556448 "   " 121690672 121820640 16 "
> [21,] "CS 13 22 "    " cfa1 121820640 124798800 " "2978160"  "7"  " 
hsa19 
> 38391408 34709332 "   " 124798800 NA NA " 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list