try this ..

df[,colnames(df)==paste("A","C",sep="")]

On Fri, Dec 3, 2010 at 12:05 PM, Yuan Jian <jayuan2...@yahoo.com> 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="")
> Error: attempt to apply non-function
>
> thanks
> Jian
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@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.
>
>

______________________________________________
R-help@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.

Reply via email to