Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread John-Paul Ferguson
Holy Cats, those were four quick responses! And the question, basically, is answered: 1. When in doubt, try quoting column names where you would try using unquoted column indexes. 2. Subset() seems, overall, the most flexible analog to Stata's variable-referencing syntax. I appreciate the help. I

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread David Winsemius
On Dec 5, 2009, at 11:30 AM, baptiste auguie wrote: Hi, Try this, cor(pollute[ ,c("Pollution","Temp","Industry")]) and ?"[" in particular, "Character vectors will be matched to the names of the object " John-Paul; In the time it took me to compose this, I see that others have already po

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread Marc Schwartz
Alternatively, you can use subset(), which supports the ":" operator for the 'select' argument: > cor(subset(iris, select = Sepal.Length:Petal.Length)) Sepal.Length Sepal.Width Petal.Length Sepal.Length1.000 -0.11756980.8717538 Sepal.Width-0.1175698 1.000 -

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread Jorge Ivan Velez
Dear John-Paul, Take a look at https://stat.ethz.ch/pipermail/r-help/2009-July/204027.html It contains different ways to do (in part) what you want. HTH, Jorge On Sat, Dec 5, 2009 at 11:22 AM, John-Paul Ferguson <> wrote: > I apologize for how basic a question this is. I am a Stata user who > h

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread Ista Zahn
As baptiste noted, you can do cor(pollute[ ,c("Pollution","Temp","Industry")]). But cor(pollute[,"Pollution":"Industry"]) will not work. For that you can do cor(pollute[ ,which(names(pollute)=="Pollution"):which(names(pollute)=="Industry")]) -Ista On Sat, Dec 5, 2009 at 11:22 AM, John-Paul

Re: [R] Referencing variable names rather than column numbers

2009-12-05 Thread baptiste auguie
Hi, Try this, cor(pollute[ ,c("Pollution","Temp","Industry")]) and ?"[" in particular, "Character vectors will be matched to the names of the object " HTH, baptiste 2009/12/5 John-Paul Ferguson : > I apologize for how basic a question this is. I am a Stata user who > has begun using R, and th

[R] Referencing variable names rather than column numbers

2009-12-05 Thread John-Paul Ferguson
I apologize for how basic a question this is. I am a Stata user who has begun using R, and the syntax differences still trip me up. The most basic questions, involving as they do general terms, can be the hardest to find solutions for through search. Assume for the moment that I have a dataset tha