[R] merge some columns

David Winsemius dwinsemius at comcast.net
Fri Sep 2 15:30:02 CEST 2011


On Sep 2, 2011, at 8:34 AM, Joao Fadista wrote:

> Dear all,
>
> I would like to know how to merge columns like:
>
> Input file:
>  V1 V2 V3 V4 V5 V6
> 1  G  A  G  G  G  G
> 2  A  A  G  A  A  G
>

Looked like an mapply-type problem:

 > with(dat,
       mapply(paste,
                list(V1, V3, V5),
                list(V2, V4, V6),
                MoreArgs=list(sep="/") )
        )

      [,1]  [,2]  [,3]
[1,] "G/A" "G/G" "G/G"
[2,] "A/A" "G/A" "A/G"


> Desired output file:
>    V1  V2   V3
> 1  G/A G/G G/G
> 2  A/A G/A A/G
>
> So for every 2 consecutive columns merge their content into one.
> Thanks in advance.
>
>
> 	[[alternative HTML version deleted]]
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list