[R] Sorting a data frame with values of different lengths

William Armstrong William.Armstrong at noaa.gov
Tue Jun 7 16:01:06 CEST 2011


Hi Sarah,

str(W_table) gives me:

> str(W_table)
'data.frame':   11 obs. of  3 variables:
 $ pds_gagehandles.i.: Factor w/ 1 level "mibe": 1 1 1 1 1 1 1 1 1 1 ...
 $ p                 : chr  "1" "2" "3" "4" ...
 $ W                 : chr  "746" "870.5" "767" "1066" ...

here is the script I am using, with the lines that create W and the W_table
bolded:

for(i in 1:length(pds_gagehandles)){
	POTWY<-get(paste(pds_gagehandles[i],"_POTWY",sep=""))
	num_wyrs<-length(POTWY)
	pre70wyrs_ind<-1:(length(POTWY)-39)
	post70wyrs_ind<-(length(POTWY)-38):length(POTWY)

	for(p in 1:11){
		if(p==1){
			pre70_POTWY<-POTWY[pre70wyrs_ind]
			post70_POTWY<-POTWY[post70wyrs_ind]
			original_stats<-wilcox.test(pre70_POTWY,post70_POTWY)
			W<-original_stats$statistic
			W_table<-data.frame(pds_gagehandles[i],p,W)		
W_table_name<-paste(pds_gagehandles[i],"_W_table",sep="")
		}else{
			sample_POTWY<-sample(POTWY)
			sample_pre70_POTWY<-sample_POTWY[pre70wyrs_ind]
			sample_post70_POTWY<-sample_POTWY[post70wyrs_ind]
			sample_stats<-wilcox.test(sample_pre70_POTWY,sample_post70_POTWY)
			sample_W<-sample_stats$statistic
			sample_info<-c(pds_gagehandles[i],p,sample_W)
			W_table<-rbind(W_table,sample_info)			
if(p==1001){
				assign(W_table_name,W_table)
			
write.table(W_table,col.names=c('gage_handle','iteration','W'),file=paste(W_table_name,".txt",sep=""),sep="\t",row.names=FALSE)
			}
		}
	}
}

Thank you very much for your help.

Billy

--
View this message in context: http://r.789695.n4.nabble.com/Sorting-a-data-frame-with-values-of-different-lengths-tp3579653p3579680.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list