如何选择特定行;具体列名;和另一组基于向量的特定列名?
我的数据:
#my data
ID<-c(1,2,3,4,5,6)
Month<-c('Jan','Jan','Mar','Feb','Mar','Jan')
Number<-c(6,5,4,3,2,1)
Color<-c('Red','Red','Blue','Green','Green','Purple')
Q1<-c(0,1,NA,1,0,1)
Q2<-c(1,1,NA,1,NA,1)
Q3<-c(NA,0,0,1,0,1)
mydata<-cbind.data.frame(ID,Month,Number,Color,Q1,Q2,Q3)
#my vector:
Jan.vector<-c('Q1','Q3')
我有(mydata):
答案 0 :(得分:1)
如果我理解正确的话:
function IsWordDocumentOpen(FileName: string): Boolean;
var
OleMessageFilter: IOleMessageFilter;
WordApp: TWordApplication;
I: Integer;
begin
Result := False;
try
OleMessageFilter := IOleMessageFilter.Create;
OleMessageFilter.RegisterFilter;
WordApp := TWordApplication.Create(nil);
try
WordApp.Connect;
for I := 1 to WordApp.Documents.Count do
begin
if WordApp.Documents.Item(I).FullName = FileName then
begin
Result := True;
System.Break;
end;
end;
finally
OleMessageFilter.RevokeFilter;
FreeAndNil(WordApp);
FreeAndNil(OleMessageFilter);
end;
finally
//
end;
end;
或 - 您可以通过以下方式说明月份或月份:
> monthNum <- 1
> wantedCol <- c('ID','Month','Color','Q1','Q3')
> mydata[ mydata$Month==substring(month.name[monthNum],1,3),match(wantedCol,names(mydata))]
ID Month Color Q1 Q3
1 1 Jan Red 0 NA
2 2 Jan Red 1 0
6 6 Jan Purple 1 1
或者您可以按索引说明您的列:
> monthName <- c('Jan','Mar')
> wantedCol <- c('ID','Month','Color','Q1','Q3')
> mydata[ mydata$Month %in% monthName,match(wantedCol,names(mydata))]
ID Month Color Q1 Q3
1 1 Jan Red 0 NA
2 2 Jan Red 1 0
3 3 Mar Blue NA 0
5 5 Mar Green 0 0
6 6 Jan Purple 1 1
或者如果您总是想要ID,月和颜色:
> monthName <- c('Jan','Mar')
> wantedCol <- c(1,2,4,5,7)
> mydata[ mydata$Month %in% monthName,wantedCol]
ID Month Color Q1 Q3
1 1 Jan Red 0 NA
2 2 Jan Red 1 0
3 3 Mar Blue NA 0
5 5 Mar Green 0 0
6 6 Jan Purple 1 1