# Hello, # I have a list with 6 categories and with different numbers of rows. # I would like to change each of them into a unique data frame in order to match # values with other data frames and perform some calculations. # Or I could make each category or list element have the same number of rows and create one large data.frame. # below is a creation of a sample list # I apologize for the length in creating the list it is the only way i could figure # out how to convey my puzzle. If you scroll down you will find it as " list.sample." Loci<-4 Pairwise<- (Loci*(Loci-1))/2 #Creation of list elements c1<- c(1,4,3,2,4,1,3,2,4,3) c2<- c(2,4,3,4,2,3,4,1,3,2) c3<- c(1,3,2,4,4,3,4,4,2,2) c4<- c(2,3,2,3,1,3,2,4,4,3) c5<- c(1,2,1,1,2,2,3,3,2,1) c6<- c(3,2,4,3,1,1,2,3,3,4) c7<- c(1,2,1,2,3,2,3,2,1,2) c8<- c(1,2,2,3,2,3,3,4,1,2) List.elements<-cbind(c1,c2,c3,c4,c5,c6,c7,c8) #Locus 1 L1.pairwise.columns <- matrix(3:ncol(List.elements), byrow=TRUE, ncol=2) Loc1.gamete.counts<- apply(L1.pairwise.columns , 1, function(.row){ paste(List.elements[,1:2], List.elements[,.row]) }) #Locus2 L2.pairwise.columns <- matrix(5:ncol(List.elements), byrow=TRUE, ncol=2) Loc2.gamete.counts<- apply(L2.pairwise.columns , 1, function(.row){ paste(List.elements[,3:4], List.elements[,.row]) }) #Locus3 L3.pairwise.columns <- matrix(7:ncol(List.elements), byrow=TRUE, ncol=2) Loc3.gamete.counts<- apply(L3.pairwise.columns , 1, function(.row){ paste(List.elements[,5:6], List.elements[,.row]) }) ##Creation of the List Gamete.pairs<-cbind(Loc1.gamete.counts,Loc2.gamete.counts,Loc3.gamete.counts ) Gamete.pairs Gamete.list<-list(1,2,3,4,5,6) for (i in 1:Pairwise){ Gamete.list[[i]]<-table(Gamete.pairs[,i]) } Gamete.list #### Gamete Frequency list.sample<-list(1,2,3,4,5,6) for (j in 1:Pairwise){ list.sample[[j]]<- Gamete.list[[j]]/(2*Genetic.Sample.Size) } ######## Here is the Sample List list.sample # I would like to have a flexible way to turn all six element in my list # into separate data frames so i can do some calculations # the only way i can figure out how to do this is "one by one" in very clunky fashion. # here is an example of my code sample.df1 <-data.frame(list.sample[[1]]) sample.df2 <-data.frame(list.sample[[2]]) sample.df3 <-data.frame(list.sample[[3]]) sample.df4 <-data.frame(list.sample[[4]]) sample.df5 <-data.frame(list.sample[[5]]) sample.df6 <-data.frame(list.sample[[6]]) sample.df1 sample.df2 sample.df3 sample.df4 sample.df5 sample.df6 # In the future i will have up to 1,200 of these small dataframes to create. # is there a way to loop through the list and create many small data frames?? # or perhaps make each of the list elements the same length and create one large data frame?? # any help or ideas would be greatly appreciated # thanks in advance Luke Neraas lukasneraas.r@gmail.com University of Alaska Fairbanks School of Fisheries and Ocean Sciences 11120 Glacier Highway UAF Fisheries Division Juneau, AK 99801 [[alternative HTML version deleted]]