[R] store the results of two connected and "disturbed" for-loops to data.frame

Thomas Schu th.schumann at gmx.de
Wed Aug 15 17:24:50 CEST 2012


Dear all,

here is a example of my problem:

/#data#
g<-c(1,1,1,2,2,2)
A<-runif(6,min=1,max=5)
B<-runif(6,min=100,max=1000)
C<-runif(6,min=30,max=31)
D<-runif(6,min=67,max=98765)
var<-cbind(A,B,C,D)
label<-colnames(var)

store<-data.frame(matrix(ncol=2))
colnames(store)=c("usedVar","prediction")

library(MASS)#get lda

for (i in c(1:4))
{
	for (k in c(1:4))
	{
	if(i==k)break()#using the same variable will not work in lda

	dis<-lda(g~var[,i]+var[,k],CV=TRUE,fold=6)#linear discriminant function
	ct<-table(g,dis$class)
	pre<-sum(diag(prop.table(ct)))# Prediction of cv-reclassification

	#store the results
	*a<-i+4*(k-1)*
	store[a,1]<-paste(label[i],label[k])
	store[a,2]<-round(pre,4)
	}
}
store/

I have got two for-loops getting "disturbed" by an if-break-case (disturbed
means, that I don´t need the information for these cases).
By using /*a<-i+4*(k-1)*/ for storing results to my "result"data.frame,  the
break-cases will be included as NA too.
*Are there a way to store my loop-results without the NA-cases to get an
continous dataset??? *

I´m pleased about every suggestion.

Thank you and best regards
Thomas







--
View this message in context: http://r.789695.n4.nabble.com/store-the-results-of-two-connected-and-disturbed-for-loops-to-data-frame-tp4640374.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list