On Dec 3, 2010, at 4:14 AM, Keith Jewell wrote:
or even shorter
df[,paste("A","C",sep="")]
Other grepping methods that generalize better to partial matches:
df[ , grep("^AC$", colnames(df))]
df[ grep("^AC$", colnames(df)) ]
--
David.
"Santosh Srinivas" wrote in message
news:aanlktikc
or even shorter
df[,paste("A","C",sep="")]
"Santosh Srinivas" wrote in message
news:aanlktikcjy7bvyfbwuwmrq4dhg4pbdau+qh_7+k+b...@mail.gmail.com...
try this ..
df[,colnames(df)==paste("A","C",sep="")]
On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian wrote:
> Hello,
>
> I tried to use a variable to
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 :
try this ..
df[,colnames(df)==paste("A","C",sep="")]
On Fri,
try this ..
df[,colnames(df)==paste("A","C",sep="")]
On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian wrote:
> Hello,
>
> I tried to use a variable to refer colname, but I got error, could anyone
> give me advice?
>
>>df=data.frame(cbind(AB=1:3,AC=3:5))
>> df$AC
> [1] 3 4 5
>> df$paste("A","C",sep=""
4 matches
Mail list logo