如果这是重复的,我很抱歉,我在任何地方都找不到它..
假设我有一堆数据框,我想将它们的所有列名都转换为小写。最有效的方法是什么?这很简单,assign
但get
我想知道是否有更快的方法?
如果我刚刚得到ChickWeight
and mtcars
,那么非动态操作将只是..
names( ChickWeight ) <- tolower( names( ChickWeight ) )
names( mtcars ) <- tolower( names( mtcars ) )
..然后我将如何使这个过程动态化,但我想知道是否有更有效的解决方案?
# column headers contain uppercase
head(ChickWeight)
# start with a vector of data frame names..
# this might contain many, many data frames
tl <- c( 'ChickWeight' , 'mtcars' )
# loop through each data frame name..
for ( i in tl ){
# save it to a temporary object name
x <- get( i )
# main operations here..
# perform the operation(s) you want to run on each data frame
names( x ) <- tolower( names( x ) )
# ..end of main operations
# assign the updated data frame to overwrite the original data frame
assign( i , x )
}
# no longer contains uppercase
head(ChickWeight)