Skip to content

select partial name and full name columns

2 messages · Irucka Embry, arun

#
Hi,
You can use the same code:
set.seed(15)
?dat1<-data.frame(sample(1:10,5,replace=TRUE),sample(20:30,5,replace=TRUE),sample(1:15,5,replace=TRUE),sample(1:8,5,replace=TRUE),datetime=as.POSIXct(paste(rep("6/3/2011",5),c("0:00","0:30","0:35","0:40","0:45")),format="%m/%d/%Y %H:%M"))

?colnames(dat1)[1:4]<-c("01_00060_00003","01_000060_00003_cd","15_000060_00003","15_00060")


dat1
#? 01_00060_00003 01_000060_00003_cd 15_000060_00003 15_00060
#1????????????? 7???????????????? 30?????????????? 2??????? 7
#2????????????? 2???????????????? 28????????????? 10??????? 4
#3???????????? 10???????????????? 22?????????????? 8??????? 8
#4????????????? 7???????????????? 27????????????? 11??????? 2
#5????????????? 4???????????????? 29????????????? 13??????? 7
? # ????????? datetime
#1 2011-06-03 00:00:00
#2 2011-06-03 00:30:00
#3 2011-06-03 00:35:00
#4 2011-06-03 00:40:00
#5 2011-06-03 00:45:00


dat1[,c("datetime",colnames(dat1)[grep("00060_00003",colnames(dat1))])]
#???????????? datetime 01_00060_00003 01_000060_00003_cd 15_000060_00003
#1 2011-06-03 00:00:00????????????? 7???????????????? 30?????????????? 2
#2 2011-06-03 00:30:00????????????? 2???????????????? 28????????????? 10
#3 2011-06-03 00:35:00???????????? 10???????????????? 22?????????????? 8
#4 2011-06-03 00:40:00????????????? 7???????????????? 27????????????? 11
#5 2011-06-03 00:45:00????????????? 4???????????????? 29????????????? 13


A.K.