lapply - R how to change dafaframe column name by using listname -
i have list y below. want change first column name of each data frame (rn) name of data frame (sa, ta). y1.
> y $sa rn x1 x2 x3 x4 x5 x6 1: timepoint 0 3.75 4.25 4.5 4.75 5 2: plot 234 304 285 279 256 238 $ta rn x7 x8 x9 x10 x11 x12 1: timepoint 0 5 4.25 3.75 4.75 4.5 2: plot 208 299 272 261 254 218 > y1 $sa sa x1 x2 x3 x4 x5 x6 1: timepoint 0 3.75 4.25 4.5 4.75 5 2: plot 234 304 285 279 256 238 $ta ta x7 x8 x9 x10 x11 x12 1: timepoint 0 5 4.25 3.75 4.75 4.5 2: plot 208 299 272 261 254 218
those list elements data tables, should simple
y1 <- map(setnames, y, "rn", names(y))
replace "rn"
1
if want index first column instead of column name "rn".
Comments
Post a Comment