Question: Split and join strings in a column using R
0
gravatar for jd
4.3 years ago by
jd0
Belgium
jd0 wrote:

    row.names X33 X40 X46 X50 X60 X80 X90 X100 X130 X200
    INTERGENIC-chrI-188881-G-C    0.37    0.41    0.48    0.45    0.47    0.42    0.45    0.44    0.40    0.36    0.36    0.33    0.39
    INTERGENIC-chrI-188939-A-G    0.38    0.48    0.56    0.54    0.57    0.45    0.57    0.51    0.49    0.47    0.41    0.38    0.52
    INTERGENIC-chrXIII-191990-A-T    0.14    0.15    0.15    0.22    0.16    0.16    0.15    0.31    0.11    0.23    0.12    0.12    0.19
    SDS3-chrIX-202625-T-G    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.00    0.33    0.35    0.41    0.50    0.53
    INTERGENIC-chrVIII-236987-G-A    0.15    0.34    0.28    0.28    0.22    0.12    0.15    0.25    0.27    0.24    0.13    0.13    0.25
    INTERGENIC-chrVIII-236993-T-A    0.12    0.25    0.21    0.19    0.17    0.00    0.00    0.18    0.16    0.17    0.08    0.11    0.12


I have a matrix [34,11] with column names: 

    row.names X33 X40 X46 X50 X60 X80 X90 X100 X130 X200 

The first column,`row.names` needs to be split into individual columns:

    GENE, CHROMOSOME, POSITION, REF, ALT (INTERGENIC-chrI-188881-G-C)

I am currently using R to get the desired output.

    library(reshape2)    
    A <- colsplit(df$row.names, "\\-", names=c("GENE", "CHROMOSOME", "POSITION", "REF", "ALT"))

I would like to perform this operation for all individual rows in the matrix. Could any one help me output a matrix as above with the new columns added. Thanks

snp string split R • 1.7k views
ADD COMMENTlink modified 4.3 years ago • written 4.3 years ago by jd0
2
gravatar for Wolfgang Maier
4.3 years ago by
Germany
Wolfgang Maier600 wrote:

Well, this isn't exactly Galaxy-related, but

can't you just use cbind() like so:

 

cbind(A, df[, 2:11])

 

Wolfgang

ADD COMMENTlink written 4.3 years ago by Wolfgang Maier600

Thanks. 

ADD REPLYlink modified 4.3 years ago • written 4.3 years ago by jd0

that does not make sense to me. Can you try:

class(A) ,

dim(A) and

dim(df)

and post what the results are?

ADD REPLYlink written 4.3 years ago by Wolfgang Maier600
0
gravatar for jd
4.3 years ago by
jd0
Belgium
jd0 wrote:

I messed up in the previous step. Thanks a lot for your help.

ADD COMMENTlink written 4.3 years ago by jd0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 172 users visited in the last hour