Hi, My data has column names which has ` character. For example , *> names(dataframe) [1] "`region" "farmsize`" "farmincome" "maincrop" "claimvalue"* If i use these objects in my function, the following error is thrown. *lmm<-lm(``region`~farmincome) Error: attempt to use zero-length variable name* Is there a way, say an escape sequence or something similar in which we can give these objects with the colnames to R functions? Thanks in advance. Regards, Raji -- View this message in context: http://r.789695.n4.nabble.com/Column-names-containing-in-R-tp4648553.html Sent from the R help mailing list archive at Nabble.com.
Hello, Can't you remove the backquotes from names(df)? If so, you can do it with x <- c("`region", "farmsize`", "farmincome", "maincrop", "claimvalue") newx <- gsub("\\`", "", x) Hope this helps, Rui Barradas Em 06-11-2012 13:21, Raji escreveu:> Hi, > > My data has column names which has ` character. For example , > *> names(dataframe) > [1] "`region" "farmsize`" "farmincome" "maincrop" "claimvalue"* > > If i use these objects in my function, the following error is thrown. > > *lmm<-lm(``region`~farmincome) > Error: attempt to use zero-length variable name* > > Is there a way, say an escape sequence or something similar in which we can > give these objects with the colnames to R functions? > > Thanks in advance. > > Regards, > Raji > > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Column-names-containing-in-R-tp4648553.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.
On Nov 6, 2012, at 5:21 AM, Raji wrote:> Hi, > > My data has column names which has ` character. For example , > *> names(dataframe) > [1] "`region" "farmsize`" "farmincome" "maincrop" "claimvalue"* > > If i use these objects in my function, the following error is thrown. > > *lmm<-lm(``region`~farmincome) > Error: attempt to use zero-length variable name* > > Is there a way, say an escape sequence or something similar in which we can > give these objects with the colnames to R functions?The mathod used inread.table is to call make.names()> make.names(x)[1] "X.region" "farmsize." [3] "farmincome" "maincrop" [5] "claimvalue" -- David Winsemius, MD Alameda, CA, USA