5

I have a data that looks like this:

> read.table("http://dpaste.com/1491018/plain/",header=TRUE)
        Probes Gene.symbol Stim1 Stim2 Stim3 Stim4
1   1415670_at        Copg 1.133 1.049 1.013 1.124
2   1415671_at    Atp6v0d1 1.068 1.006 1.082 1.234
3   1415672_at      Golga7 1.010 0.883 1.061 1.029
4   1415673_at        Psph 0.943 0.799 0.982 1.064
5 1415674_a_at     Trappc4 1.048 0.960 1.191 1.118
6   1415675_at        Dpm2 1.053 1.104 1.053 1.057

What I want to do is to create a new data frame that combines first two column and turn it into row names,

                     Stim1 Stim2 Stim3 Stim4
1415670_at-Copg      1.133 1.049 1.013 1.124
1415671_at-Atp6v0d1  1.068 1.006 1.082 1.234
1415672_at-Golga7    1.010 0.883 1.061 1.029
1415673_at-Psph      0.943 0.799 0.982 1.064
1415674_a_at-Trappc4 1.048 0.960 1.191 1.118
1415675_at-Dpm2      1.053 1.104 1.053 1.057

How can this be done?

pdubois
  • 7,640
  • 21
  • 70
  • 99

2 Answers2

8

Try this:

 dat <- read.table("http://dpaste.com/1491018/plain/",header=TRUE)
 rownames(dat) <- do.call(paste,c(dat[c("Probes","Gene.symbol")],sep="-"))
 dat <- dat[,!names(dat) %in% c("Probes","Gene.symbol")] 
 dat

Result:

>      dat
                     Stim1 Stim2 Stim3 Stim4
1415670_at-Copg      1.133 1.049 1.013 1.124
1415671_at-Atp6v0d1  1.068 1.006 1.082 1.234
1415672_at-Golga7    1.010 0.883 1.061 1.029
1415673_at-Psph      0.943 0.799 0.982 1.064
1415674_a_at-Trappc4 1.048 0.960 1.191 1.118
1415675_at-Dpm2      1.053 1.104 1.053 1.057
neversaint
  • 60,904
  • 137
  • 310
  • 477
  • Why do you need this `dat <- dat[,!names(dat) %in% c("Probes","Gene.symbol")]` ? To me it works already just with `rownames(dat) <- do.call(paste,c(dat[c("Probes","Gene.symbol")],sep="-"))` but I might be wrong. – Al14 Aug 16 '15 at 19:12
2

3 years later, but it is very simple.

row.names(http://dpaste.com/1491018/plain/)<-paste(Probes,Gene.symbol, sep="-")