Rename multiple lists items in for loop

I have multiple list with the same amount of items. I want to rename all lists items in loop. For example from lists items names "a, b, c", I want to rename them to "first, second, third": #create 3 lists with items names a, b, c list1 <- list(a=c(1:10), b=c(1:5), c=c(1:3)) list2 <- list(a="a", b="b",… Read More Rename multiple lists items in for loop

pandas index rename using dictionary

Is there a version of this but using a dictionary instead of a list? Following the example in the link what I want to do is idx.rename({‘kind’:’species’}). If it matters, this is how my data frame looks like: k_CFD (%) k_CFD (%) error run_name CFD 20230104124758_TI107_HDO6034-MS_WithInterpolati… DUT 68.529412 9.576598 MCP-PMT 72.058824 21.711526 20230104124758_TI107_HDO6034-MS_WithInterpolati… DUT 77.647059… Read More pandas index rename using dictionary

Rename vars with numeric names

Say I have a dataframe with variables that have numeric names that I want to rename by adding character prefixes. country <- c("country","US","France") var1 <- c(234234,234234,1233124) var2 <- c(34534,25674,123124) df <- data.frame(country,var1,var2) %>% rename(‘2021′ = var1,’2022’ = var2) Country 2021 2022 country 234234 34534 US 234234 25674 France 1233124 123124 Example table is weird, sorry.… Read More Rename vars with numeric names

How to change the names of columns of a list of dataframes?

I have this list of dataframes created as follows : df = data.frame(x = c(1,0,0,0,1,1,1,NA), y = c(2,2,2,2,3,3,2,NA), z = c(1:7,NA), m = c(1,2,3,1,2,3,1,NA) ) df$x = factor(df$x) df$y = factor(df$y) df$m = factor(df$m) l1 = list(df$x,df$y,df$m) l2 = lapply(l1,table) l3 = lapply(l2,as.data.frame) l3 The output is as follows : [[1]] Var1 Freq 1 0… Read More How to change the names of columns of a list of dataframes?

Dplyr: Rename multiple variables with regex by name

I need to rename multiple variables using a replacement dataframe. This replacement dataframe also includes regex. I would like to use a similar solution proposed here, .e.g df %>% rename_with(~ newnames, all_of(oldnames)) MWE: df <- mtcars[, 1:5] # works without regex replace_df_1 <- tibble::tibble( old = df %>% colnames(), new = df %>% colnames() %>%… Read More Dplyr: Rename multiple variables with regex by name

Rename variables (columns) in datasets that are in a list – R

I have a list of datasets with different variables. I need to rename them according to the naming convention in the name dataframe below. df1 <- data.frame(x1= c(1,2,3), x2=c(1,2,3)) df2 <- data.frame(x1= c(1,2,3), x3=c(1,2,3)) df3 <- data.frame(x4= c(1,2,3), x5=c(1,2,3)) mylist <- list(df1,df2,df3) name <- data.frame(old= c("x1","x2","x3","x4","x5"), new=c("A","B","A","A","C")) I can do this one by one, but… Read More Rename variables (columns) in datasets that are in a list – R