I am having . problem i would very much appreciate some help with! It involves a for loop on two levels (explained below) and then concatenating the individual results from each iteration of 'i' in to one data frame..
I have an R object within which I have some metadata. I want to access some stats using the table function (which works fine).. The call looks like this:
This works fine and give me a nice breakdown of how many elements from cluster 2 belong to filename The problem is the length of clusters and filename. It would be too time consuming to this many times.
cluster length = 20
filename=11
What i would like to do is generate a for loop that gives me the statistics above by iterating through elements of i and the concatenate these individual results in to one dataframe.
I am comfortable using for loops, however I have never been in a situation where I need to iterate through two elements at the same time:
clusters<-1:20
filename<-1:11
for (i in cluster) {
x<- table(object@metadata$cluster== i & (object@metadata$filename == **????**)
print(x)
}
I am not sure how to implement this loop to go through i and "j" which would be after file name...
What i would then like to do is concatenate all the results in to one data frame similar to:
x<-rbind(x)
print(x)
with the names of i in the cluster and filename as the titles to the respective columns..
I am not understanding exactly what you want to accomplish. To answer the question of how to iterate over two indices:
clusters<-1:20
filename<-1:11
for (i in clusters) {
for (j in filename) {
x<- table(object@metadata$cluster== i & (object@metadata$filename == j)
print(x)
# or
#print(paste(i, j, x)
}
}
However, I think you would get the same information from
If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it: