我正在嘗試創建一個將執行一系列分析的循環。我使用geepack中的geeglm,如果有任何空值,則失敗。創建子集解決了這個問題,但似乎無法根據變化的變量動態設置子集。R - 使用變量創建子集數據框
while (j <= y.num) {
strSubset = as.character(df.IV$IV[j]) #Gives column name in quotes
df.data.sub = subset(df.data, strSubset>=0)
#subset dataset is not created
# analyses on subset take place
j = j + 1
}
如果鍵入它工作在公式中的變量名,所以我假定我不是以這樣的方式,允許其在所述子集的功能進行評價創建變量。任何幫助將不勝感激!
重複的例子:
# dataset
age<-18:29
height<-58:69
df.ex=data.frame(age=age,height=height)
df.ex[4,1]<-NA
# dataset of columns that will be used for analysis
values<-c("age", "height")
df.variables=data.frame(values)
# Age column has a null (NA) value. The row must be removed for the analysis to run
# explicit creation
df.ex.sub.explicit<-subset(df.ex, age >= 0)
dim(df.ex.sub.explicit) #11 obs of 2 variables
i=1
strFilter=as.character(df.variables$values[i])
df.ex.sub.passvar<-subset(df.ex,strFilter>=0)
dim(df.ex.sub.explicit) #12 obs of 2 variables
請不要在這裏和r-help郵件列表上交叉發帖:它會導致多餘的努力... –