[R] replace column headers

2008-06-17 Thread Paul Adams




Hello everyone,=I have a question as to how to remove the column headers
in a data file and then replace those with titles from another file in this case
the file labeled ann  (
in which the titles are all in one column).I am unsure which function to
use.I tried rm () to remove the column headers but they are numbers and
 the error message said to only use rm for charactors not numbers
Below is the code I used, I abbreviated the file path. 
dat-read.table(file=C:\\Documents and Settings\\txt,header=F,row.names=1)
x.df-as.data.frame(dat)
rm(dat[,1])
file.show(file=C:\\Documents and
Settingstxt)
ann-read.table(C:\\Documents and Settings\\..txt=)
file.show(file=C:\\Documents and Settings\\...txt)
Any help would be appreciated   
Paul


  
[[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.


Re: [R] replace column headers

2008-06-17 Thread Esmail Bonakdarian

Paul Adams wrote:



Hello everyone,=I have a question as to how to remove the column headers
in a data file and then replace those with titles from another file in this case
the file labeled ann  (
in which the titles are all in one column).


Maybe this will help partially.

I am not sure on how to read your new column names from a file into a vector
but if you can get them into that format this should let you accomplish your
goal.

Esmail



 load(Data/simpleTestData2.rda)

 df
   Y X1   X2   X3 X4 X5 X6
1   74.9 10 49.8  0.2 99 50 57
2   79.8 11 49.6  0.4 69 91 57
3   84.4 12 48.8  1.2 30 38 58
4   88.8 13 47.6  2.4 77 87 58

 colnames(df)
[1] Y  X1 X2 X3 X4 X5 X6

 altnames=c(A, B1, B2, B3, B4, B5, B6)

 colnames(df)=altnames

 df
   A B1   B2   B3 B4 B5 B6
1   74.9 10 49.8  0.2 99 50 57
2   79.8 11 49.6  0.4 69 91 57
3   84.4 12 48.8  1.2 30 38 58
4   88.8 13 47.6  2.4 77 87 58

 save(df, file=example.rda)

# new file will contain the new column headers.

__
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.