On 21.11.2011 11:40, Joel wrote:
Hi fellow R users.
I have a problem when i try to change the Names of the columns on a dataset:
The names of the names dataset looks like this:
toPlot
names(toPlot)
[1] "REPORT_20" "REPORT_21" "REPORT_22" "REPORT_23"
[5] "REPORT_24" "REPORT_25" "REPORT_QREP001" "REPORT_RS010"
[9] "REPORT_RS011" "REPORT_RS030" "REPORT_RS090" "REPORT_RS110"
[13] "REPORT_RS120" "REPORT_RS121" "REPORT_RS122" "REPORT_RS130"
[17] "REPORT_RS131" "REPORT_RS140" "REPORT_RS141"
Then I got an dataset with correspondent texts
text
ID
TEXT
1 REPORT_RS010_D
Statusrapport
2 REPORT_RS011_D
Ifyllnad
3 REPORT_RS030_D
Export
4 REPORT_RS090_D
Uppföljning
5 REPORT_RS110_D
Guidelines
6 REPORT_RS120_D Korstabulering - en
gruppvariabel
7 REPORT_RS121_D Korstabulering - jämförelse med andra
enheter
8 REPORT_RS122_D Korstabulering- två klassvariabler och jämförelse med
andra
9 REPORT_RS130_D
Sjukdomar
10 REPORT_RS131_D Sjukdomar och en
gruppvariabel
11 REPORT_RS140_D
Operationer
12 REPORT_RS141_D Operationer och en
gruppvariabel
I what i want is to change the names of toPlot with the real texts so I
tried this:
names(toPlot)[names(toPlot)=="REPORT_RS140"]<-text[text$ID==paste("REPORT_RS140","_D",sep=""),2];
that gave me this strange result
names(toPlot)
[1] "REPORT_20" "REPORT_21" "REPORT_22" "REPORT_23"
[5] "REPORT_24" "REPORT_25" "REPORT_QREP001" "REPORT_RS010"
[9] "REPORT_RS011" "REPORT_RS030" "REPORT_RS090" "REPORT_RS110"
[13] "REPORT_RS120" "REPORT_RS121" "REPORT_RS122" "REPORT_RS130"
[17] "REPORT_RS131" "7" "REPORT_RS141"
As you can see I got the number 7 instead of the text and I dont know why.
Can anyone spot the error?
Probably the entries in your "text" objects are factors which have been
converted to numeric on the last assignment? Try to as.character()
before doing these assignments if factors are inappropriate anyway.
Best,
Uwe Ligges
//joel
--
View this message in context:
http://r.789695.n4.nabble.com/Change-names-on-dataset-tp4091154p4091154.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.