Try this:

do.call(cbind, lapply(a[2:ncol(a)], function(x)do.call(rbind,
strsplit(as.character(x), ''))))

On Wed, Jun 3, 2009 at 10:39 AM, Duijvesteijn, Naomi <
naomi.duijveste...@ipg.nl> wrote:

>
>   Hi,
>
>
>   I am trying to split multiple columns. One column works just fine, but I
>   want to do it for multiple columns…
>
>
>   Example
>
>   > a
>
>    ID V2 V3 V4 V5 V6 V7 V8 V9 V10
>
>   1 PBBA0644 -- GG AA -- AA -- AA GG  GG
>
>   2 PBBA1010 -- GG AA -- AA -- AA GG  GG
>
>   3 0127ATPR -- GG AA -- AA -- AA GG  GG
>
>   4 0128EHAB  -- GG AA -- AG -- AA AG  GG
>
>   5 PBBA0829 -- GG AA -- AA -- AA GG  AG
>
>   6 01605BGA -- GG AA -- AA -- AA GG  GG
>
>   7 01624BGA -- GG AA -- AG -- AA GG  GG
>
>   8 01853BGA -- GG AA -- AG -- AA GG  GG
>
>   9 BBA0949 -- GG AA -- AA -- AA GG  GG
>
>   10  0224LN -- GG AA -- AA -- AA GG  GG
>
>
>   For single column (works well)
>
>   b<- cbind.data.frame(do.call("rbind", strsplit(as.character(a$V2), "")))
>
>
>
>   For multiple columns:
>
>
>   for (i in 2:10)
>
>   {
>
>   b<- cbind.data.frame(do.call("rbind", strsplit(as.character(a[i]), "")))
>
>   }
>
>
>   R gives the following result
>
>
>     1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
> 28
>   29 30 31
>
>   1 c ( 4 ,   4 ,   4  ,     4  ,     3  ,     4  ,     4  ,     4  ,     4
>   ,     4  )
>
>
>   Probably a small error somewhere in my code, but don’t seem to be able to
>   solve it.
>
>
>   Thanks in advance
>
>
>   Naomi
>
>
>
>
>
>   Disclaimer:  De  informatie opgenomen in dit bericht (en bijlagen) kan
>   vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde(n).
>   Indien u dit bericht ten onrechte ontvangt, wordt u geacht de inhoud niet
> te
>   gebruiken, de afzender direct te informeren en het bericht te
> vernietigen.
>   Aan dit bericht kunnen geen rechten of plichten worden ontleend.
>
>
> ----------------------------------------------------------------------------
>   ----------------------------
>
>   Disclaimer: The information contained in this message may be confidential
>   and is intended to be exclusively for the addressee. Should you receive
> this
>   message unintentionally, you are expected not to use the contents herein,
> to
>   notify the sender immediately and to destroy the message. No rights can
> be
>   derived from this message.
>
> ______________________________________________
> R-help@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.
>
>


-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to