> txt <- "ID CA1 CA3 CA2 MA2 MA1 MA3
+ 1 14 15 13 7 12 3
+ 2 19 7 12 10 14 5
+ 3 21 12 19 6 8 9 "

> dta <- read.table(textConnection(txt), header=TRUE)
> dta
  ID CA1 CA3 CA2 MA2 MA1 MA3
1  1  14  15  13   7  12   3
2  2  19   7  12  10  14   5
3  3  21  12  19   6   8   9
>
# use [ <row> , <col> ] with a vector of column names in the order desired
# and leave the row entry blank

> dta[ , c("ID","CA1" ,"CA2" ,"CA3" ,"MA1" ,"MA2" ,"MA3") ]
  ID CA1 CA2 CA3 MA1 MA2 MA3
1  1  14  13  15  12   7   3
2  2  19  12   7  14  10   5
3  3  21  19  12   8   6   9

--
David Winsemius, MD
Heritage Labs

On Nov 20, 2008, at 3:28 PM, Tul Gan wrote:

Hi !
I am new to R. Can somebody help me in reformatting huge output files ,i.e, rearranging sets of columns in specific order.
For example: I have data for three compunds 1, 2 and 3
file1:
ID CA1 CA3 CA2 MA2 MA1 MA3
1 14 15 13 7 12 3
2 19 7 12 10 14 5
3 21 12 19 6 8 9

to
File 2:

ID CA1 CA2 CA3 MA1 MA2 MA3
1 14 13 15 12 7 3
2 19 12 7 14 10 5
3 21 19 12 8 6 9

or File3:
ID CA1 MA1 CA2 MA2 CA3 MA3
1 14 12 13 7 15 3
2 19 14 12 10 7 5
3 21 8 19 6 12 9

Thanks for your help,
Tul Gan


__________________________________________________________________ Ask a question on any topic and get answers from real people. Go to Yahoo! Answers and share what you know at http://ca.answers.yahoo.com
        [[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.

______________________________________________
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