r - Both extract and create names for columns within a matrix -
I have a matrix with columns representing 30 different frequency windows and rows representing rows. I want to extract each column and assign a variable to each vector and the name of that variable should be the name of that frequency window (which is the value between me, so I would like to name just like the f100 as each variable). What is the best way to write a loop to extract and nominate each variable?
If you want to create 30 variables in the global environment, the columns of the matrix , You can use list2env
or assign
(I'll probably put a list in a matrix / dataframe or even make lists and all necessary actions < / P>
list2env (loop (as.data.frame (mat), function (x) x), envir =. GlobelEnv) # environment: R_GlobalEnv> F1 # [1] 37 38 12 34 26 21 30 6 27 29
data set.seed (42) mat & lt; - mat Ix (sample (1:40, 30 * 10, location = TRUE), ncol = 30, dimnames = list (NULL, paste0 ("f", 1:30)))
set.seed (42) mat & lt; - mat Ix (sample (1:40, 30 * 10, location = TRUE), ncol = 30, dimnames = list (NULL, paste0 ("f", 1:30)))
Comments
Post a Comment