r - Restructuring a large data matrix -


i have matrix of 187,727 observations of 27 variables.

each row consists of species name , trait measurements associated name. there uneven observations each species.

i'd make reviewing matrix easier. initial thought create loop identified number of unique species names, identify how many entries there species, shift on data list of information grouped under each species name. call each set of species information review separately.

unfortunately, i've come roadblock in understanding of how this. here how far managed get:

traits <- list()  for(i in 1:length(unique(data.traits$accspeciesname))){      name <- data.traits$accspeciesname[i]        for(j in 1:sum(data.traits$accspeciesname %in% data.traits$accspeciesname[name])){            traits[i,j] <- data.traits[j,]       } } 

to see how user 42 suggesting solve this, try looking @ ?split divides data frames or matrices based on grouping factor f provide. here's small example:

data(iris) mylist = split(x = iris, f = iris$species) lapply(mylist, summary) 

more explicit code might this:

data(iris)  # using `split` ---- mylist = split(iris, iris$species)  # return rows of data frame species column equal ---- # each of unique values column takes --------------------- mylist2 = lapply(levels(iris$species), function(x) iris[iris$species == x,]) names(mylist2) = levels(iris$species) # all.equal return true  # compare 2 ways -------- all.equal(mylist, mylist2) # true 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -