Skip to content

locate the needed columns

2 messages · Hui Du, Weidong Gu

#
If the pattern is characterized by capital letters as your sample
suggests. The following code may help

df<-list()
names(d) = c("A.x", "B.x", "C.x", "A.y", "B.y", "C.y")
group.v<-matrix(NA,nrow=3,ncol=2) ### you may need to modify nrow and ncol
for (i in 1:3) {
group.v[i,]<-names(d)[grep(LETTERS[i],names(d))]
df[i]<-d[,names(d)%in% group.v[i]]
}


Weidong Gu
On Tue, Aug 30, 2011 at 2:31 PM, Hui Du <Hui.Du at dataventures.com> wrote: