JingJiang Yan
2011-Apr-18 16:38 UTC
[R] How to remove the double or single quote from a string (unquote?)?
Is there a function to get a string without a pair of quotes around it? I have several expressions like: glm(V12 ~ V3, family=binomial, data=df1) glm(V12 ~ V4, family=binomial, data=df1) ... glm(V12 ~ V8, family=binomial, data=df1) As you can see, the only differences among them are V3 ... V8. Because sometimes several of these expressions are performed many times, I want to use a variable "i" to change the V3 ... V8. I did this with: > i <- 3:8 > glm(V12 ~ paste("V", i, sep=""), family=binomial, data=df1) However, it seems the paste always returns a variable name with a pair of quotes, which were wrong in such condition. I only find a function "sQuote" to add quotes to a string, and it looks I am looking for an opposite function of it. Any advice will be appreciated.
Gerrit Eichner
2011-Apr-18 16:49 UTC
[R] How to remove the double or single quote from a string(unquote?)?
Hi, Jing Jiang, maybe as.formula( paste( "V12 ~ V", i, sep = "")) inside the call to glm() does what you need. Hth -- Gerrit On Tue, 19 Apr 2011, JingJiang Yan wrote:> Is there a function to get a string without a pair of quotes around it? > > I have several expressions like: > glm(V12 ~ V3, family=binomial, data=df1) > glm(V12 ~ V4, family=binomial, data=df1) > ... > glm(V12 ~ V8, family=binomial, data=df1) > > As you can see, the only differences among them are V3 ... V8. > Because sometimes several of these expressions are performed many times, > I want to use a variable "i" to change the V3 ... V8. I did this with: > >> i <- 3:8 >> glm(V12 ~ paste("V", i, sep=""), family=binomial, data=df1) > > However, it seems the paste always returns a variable name with a pair of > quotes, which were wrong in such condition. > I only find a function "sQuote" to add quotes to a string, and it looks I am > looking for an opposite function of it. > Any advice will be appreciated. > > ______________________________________________ > 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. >--------------------------------------------------------------------- Dr. Gerrit Eichner Mathematical Institute, Room 212 gerrit.eichner at math.uni-giessen.de Justus-Liebig-University Giessen Tel: +49-(0)641-99-32104 Arndtstr. 2, 35392 Giessen, Germany Fax: +49-(0)641-99-32109 http://www.uni-giessen.de/cms/eichner
Allan Engelhardt
2011-Apr-18 16:54 UTC
[R] How to remove the double or single quote from a string (unquote?)?
This should be a FAQ: you are confusing the value with its printed representation. Try print(paste("V", 3:8, sep=""), quote=FALSE) to see that there are no quotes, and you may want to read up on help("as.formula", package="stats") which has the examples you are searching for. Allan On 18/04/11 17:38, JingJiang Yan wrote:> Is there a function to get a string without a pair of quotes around it? > > I have several expressions like: > glm(V12 ~ V3, family=binomial, data=df1) > glm(V12 ~ V4, family=binomial, data=df1) > ... > glm(V12 ~ V8, family=binomial, data=df1) > > As you can see, the only differences among them are V3 ... V8. > Because sometimes several of these expressions are performed many times, > I want to use a variable "i" to change the V3 ... V8. I did this with: > > > i <- 3:8 > > glm(V12 ~ paste("V", i, sep=""), family=binomial, data=df1) > > However, it seems the paste always returns a variable name with a pair > of quotes, which were wrong in such condition. > I only find a function "sQuote" to add quotes to a string, and it > looks I am looking for an opposite function of it. > Any advice will be appreciated. > > ______________________________________________ > 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.