Simple way to set R column names as index

I’m new to R and looking for an easy way to get rid of column names in a R dataframe and return the names to their index [1,2,3,4..]. Something like combining .iloc and reset_index in pandas. I need the colnames initially before returning them to index so it can’t be a solution that involves the… Read More Simple way to set R column names as index

Reorder matrix columns based on colnames suffix and the order of a character vector

I have a matrix that looks like this cols <- c("foo_AFG", "baz_SYR", "baz_TUR", "foo_SYR", "foo_TUR", "baz_AFG") foo <- matrix(ncol = length(cols)) colnames(foo) <- cols w <- c("SYR", "AFG", "TUR") foo foo_AFG baz_SYR baz_TUR foo_SYR foo_TUR baz_AFG [1,] NA NA NA NA NA NA I would like to reorder the columns of foo so that the… Read More Reorder matrix columns based on colnames suffix and the order of a character vector

Correctly order/sort columns based on string in colnames tidyverse style in R

This is just a slice of a large dataframe that I have dput(MyData) structure(list(Frui1_Trea4_Ty4_0d = c(10L, 4L, 28L, 147L, 6L), Frui1_Trea4_Ty4_14d = c(18L, 0L, 26L, 70L, 27L), Frui1_Trea4_Ty8_0d = c(9L, 1L, 21L, 168L, 6L), Frui1_Trea4_Ty8_14d = c(19L, 0L, 58L, 74L, 10L), Frui2_Trea4_Ty4_0d = c(40L, 6L, 39L, 141L, 15L), Frui2_Trea4_Ty4_14d = c(74L, 1L, 91L, 24L, 8L),… Read More Correctly order/sort columns based on string in colnames tidyverse style in R