Hi, How do I rename the column labels in the table? For Instance, if I have a table like this, and I want to have the column labels changed from "A1 A2 A3 A4 A5" to "Mike Kate Michelle Paul Young" A1 A2 A3 A4 A5 1 33 44 55 66 77 2 3 4 5 6 7 7 8 9 and my text file location is: ""/Users/MAC/Desktop/data.txt" When I type in colnames(data.txt)[1] <- "Income", I get an error message saying "target of assignment expands to non-language object". Thanks!
You can't do that on disk - try:> dfr <- read.table ( "/Users/MAC/Desktop/data.txt" ) > dfrA1 A2 A3 A4 A5 1 33 44 55 66 77> colnames( dfr ) <- c( "Mike", "Kate", "Michelle", "Paul", "Young" ) > dfrMike Kate Michelle Paul Young 1 33 44 55 66 77> write.table( dfr, "/Users/MAC/Desktop/data.txt" )Rgds, Rainer On Friday 07 September 2012 22:54:32 Youn Se Hwan wrote:> Hi, > > How do I rename the column labels in the table? > > For Instance, if I have a table like this, and I want to have the column labels changed from "A1 A2 A3 A4 A5" to "Mike Kate Michelle Paul Young" > > A1 A2 A3 A4 A5 > 1 33 44 55 66 77 > 2 > 3 > 4 > 5 > 6 > 7 > 7 > 8 > 9 > > and my text file location is: ""/Users/MAC/Desktop/data.txt" > > When I type in colnames(data.txt)[1] <- "Income", I get an error message saying "target of assignment expands to non-language object". > > Thanks! > > ______________________________________________ > R-help at 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.- - - - - Boycott Apple!
You seem to be trying to do something from the file on disk and you want to do it to the table in the R environment. Example of what you probably want mydata <- sample(c("A1", "A2", "A3", "A4", "A5"), 45, replace = TRUE) mytable <- table(mydata) mytable names(mytable) <- c("Mike", "Kate", "Michelle", "Paul Young") mytable John Kane Kingston ON Canada> -----Original Message----- > From: youn.sehwan at gmail.com > Sent: Fri, 7 Sep 2012 22:54:32 -0400 > To: r-help at r-project.org > Subject: [R] How to Rename Column Labels? > > Hi, > > How do I rename the column labels in the table? > > For Instance, if I have a table like this, and I want to have the column > labels changed from "A1 A2 A3 A4 A5" to "Mike Kate Michelle Paul Young" > > A1 A2 A3 A4 A5 > 1 33 44 55 66 77 > 2 > 3 > 4 > 5 > 6 > 7 > 7 > 8 > 9 > > and my text file location is: ""/Users/MAC/Desktop/data.txt" > > When I type in colnames(data.txt)[1] <- "Income", I get an error message > saying "target of assignment expands to non-language object". > > Thanks! > > ______________________________________________ > R-help at 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.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!