r - Sorting list of matrices by the first column -
i have list containing 4 matrices, each 21 random numbers in 3 columns , 7 rows.
i want create new list using lapply function in each matrix sorted first column.
i tried:
#example info set.seed(1) list.a <- replicate(4, list(matrix(sample(1:99, 21), nrow=7))) ordered <- order(list.a[,1]) lapply(list.a, function(x){[ordered,]}) but @ first step r gives me error "incorrect number of dimensions". don't know do. works 1 matrix, though.
please help me. thanks!
you there - need iterate through list reorder each matrix.
its easier 1 lapply statement
lapply(list.a, function(x) x[order(x[,1]),]) note x in function phone call represents matrices in list.
r list sorting matrix
No comments:
Post a Comment