Entering edit mode
11.1 years ago
robjohn7000
▴
110
I have a data frame called process.yield:
process Yield
35 0.38
37 0.29
89 0.75
90 0.82
I also have results of clustering analysis with members in different groups with the following code:
for (i in 1:3){
clusterNo <- names(which(hier2==i))
filename=paste(dir, 'cluster',i,'.txt',sep="")
write(clusterNo, filename) # save cluster member names
}
An example of "clusterNo" members at each iteration:
35
89
90
But I also want to have cluster group outputs conatining group members and their yields (based on the data frame - process.yield) as follows:
process Yield
35 0.38
89 0.75
90 0.82
I tried with the following code:
for (i in 1:3){
clusterNo <- names(which(hier2==i))
members.yield <- names(which(clusterNo %in% process.yield[,1]))
colnames(members.yield) <- c("process", "Yield")
filename=paste(dir, 'cluster',i,'.txt',sep="")
write(members.yield, filename) # save cluster member names
}
This code ouputted "NULL". How can I modify the code t give the expected outputs?
Thanks
process.yield[hier2 ==i,]
Replacing this line: members.yield <- names(which(clusterNo %in% process.yield[,1])) with: process.yield[hier2 ==i,] solved the problem. Much appreciated brentp!