Skip to content

colname refered by a variable

5 messages · Yuan Jian, Santosh Srinivas, Ivan Calandra +2 more

#
try this ..

df[,colnames(df)==paste("A","C",sep="")]
On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian <jayuan2008 at yahoo.com> wrote:
#
Or simpler:
df[, paste("A","C",sep="")]
df[[paste("A","C",sep="")]]

Or:
x <- paste("A","C",sep="")
df[,x]
df[[x]]

Btw, you don't need to use cbind(), data.frame() does it already

Ivan

Le 12/3/2010 08:21, Santosh Srinivas a ?crit :

  
    
#
or even shorter
df[,paste("A","C",sep="")]


"Santosh Srinivas" <santosh.srinivas at gmail.com> wrote in message 
news:AANLkTikcJy7BVyfBwUwmRQ4dHg4pBdau+Qh_7+K+bRt2 at mail.gmail.com...
try this ..

df[,colnames(df)==paste("A","C",sep="")]
On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian <jayuan2008 at yahoo.com> wrote:
#
On Dec 3, 2010, at 4:14 AM, Keith Jewell wrote:

            
Other grepping methods that generalize better to partial matches:

df[ , grep("^AC$", colnames(df))]

df[ grep("^AC$", colnames(df)) ]

--  
David.
David Winsemius, MD
West Hartford, CT