Re: [R] How to subset data, by sorting names alphabetically.

2015-02-12 Thread Leandro Roser
Hi, a solution could be: # example matrix a: a <- matrix(1:100, 10, 10) a[, 1] <- (sample(c("aa","bb" , "ab"), 10, rep=TRUE)) a <- a[order(a[, 1]), ] # order the matrix by row = 1 #subsetting a: lev <- levels(as.factor(a[, 1])) subs <- list() for(i in 1:length(lev)) { subs[[i]] <- a[a[, 1] %

Re: [R] How to subset data, by sorting names alphabetically.

2015-02-12 Thread Greg Snow
The split function does essentially this, but puts the results into a list rather than using the dangerous and messy assign function. The overall syntax is simpler as well. On Thu, Feb 12, 2015 at 3:14 AM, Jim Lemon wrote: > Hi Samarvir, > Assuming that you want to generate a separate data fram

Re: [R] How to subset data, by sorting names alphabetically.

2015-02-12 Thread Jim Lemon
Hi Samarvir, Assuming that you want to generate a separate data frame for each value of "Name", # name of initial data frame is ssdf for(nameval in unique(ssdf$Name)) assign(nameval,ssdf[ssdf$Name==nameval,]) This will produce as many data frames as there are unique values of ssdf$Name, each name