Thank you so much. This is what I was looking for.
• 0 views
•
link
Hi there,
Is there any function to reorder "matrix" "array" based on specific criteria?
For example, I got an array with column names A to Z.
I want to reorder columns so that column names with vowels (a, e, i, o, u) appear first in the array and the rest of the letters column later.
Any thoughts
Best: Imran
assuming your array is:
library(dplyr)
ar <- t(array(data = 1:27,
dim = c(20, 3),
dimnames = list(c(sample(letters, 20)))))
class(ar)
use dplyr() to transform it in a tibble, move the columns of interest and convert back to array
ar %>% as_tibble() %>% relocate(any_of(c("a", "e", "i", "o", "u"))) %>% simplify2array()
Thank you so much. This is what I was looking for.
Log in to answer this question.