Combining first two columns and turn it into row names in R data.frame
dataframe, r
Solution
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
Problem
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?