受this answer的启发,我的目标是在m
数据集群中找到仅对一个m
(例如m[[15]]
)特定的变量,而并非其他m
。
例如,我知道变量genre == 4
仅特定于m[[15]]
(“ Fazio”,即names(m)[15]
),而genre == 4
不会出现在其他任何变量中m
个集群(由subset(d,genre == 4)
确认)。
因此,我希望输出的名称为"Fazio"
和genre == 4
。
我想对mods
中显示的所有变量而不只是genre
重复此过程吗?
我尝试了以下操作,但未成功:
d <- read.csv("https://raw.githubusercontent.com/rnorouzian/m/master/v.csv",h = T) # DATA
mods <- c("genre","cont.type","time","cf.timely","ssci","setting","ed.level",# mods
"Age","profic","motivation","Ss.aware","random.grp","equiv.grp","rel.inter","rel.intra","sourced","timed","Location","cf.scope","cf.type","error.key","cf.provider","cf.revision","cf.oral","Length","instruction","graded","acc.measure","cf.training","error.type")
m <- split(d,d$study.name) # `m` clusters of data.frames
# SOLUTION TRIED:
tmp = do.call(rbind,lapply(mods,function(x){
d = unique(d[c("study.name",x)])
names(d) = c("study.name","val")
transform(d,nm = x)
}))
# this logic may need to change:
tmp = tmp[ave(as.numeric(as.factor(tmp$val)),tmp$val,FUN = length) == 1,]
lapply(split(tmp,tmp$study.name),function(a){
setNames(a$val,a$nm)
}) # doesn't return anything