是否可以将col
变量作为数字传递到separate
函数?
从?separate
col
定义为Bare column name.
Dataframe <- data.frame(Time = rep("1:00 AM", times = 20), Place = rep("Wawa", times = 20))
Dataframe2 <- data.frame(Time2 = rep("1:00 AM", times = 20), Place = rep("Wawa", times = 20))
Data <- list(Dataframe , Dataframe2)
Dataframe %>% separate(col = Time, into = c("col_name_1NEW", "col_name_2NEW"), sep =" ") #works
Dataframe2 %>% separate(col = Time2, into = c("col_name_1NEW", "col_name_2NEW"), sep =" ") #works
for(i in 1:length(Data)){
Data[[i]] %>% separate(col = Time, into = c("col_name_1NEW", "col_name_2NEW"), sep =" ")
} #returns error because of wrong colum name for Data[[2]]
我想通过将col
参数作为列号而不是像下面那样使其更具普遍性:
for(i in 1:length(Data)){
Data[[i]] %>% separate(col = 1, into = c("col_name_1NEW", "col_name_2NEW"), sep =" ")
}
答案 0 :(得分:3)
尝试the_content()
将列名称作为字符串传递:
trigger_error("Some info",E_USER_ERROR);