0
与此相关的问题里面: Adding prefixes to some variables without touching others?分配给临时变量的`maggritr`命令链
我尝试这个解决办法,但因为我不知道发生了什么事没有分享:
数据:
df1 <- data.frame("hea_income"=c(45000,23465,89522),"gea_property"=c(1,1,2) ,"win_state"=c("AB","CA","GA"), "education"=c(1,2,3), "commute"=c(13,32,1))
溶液:
names(df1) %<>% inset(tmp<-!grepl("_",.),paste0("important_",.)[tmp])
# hea_income gea_property win_state important_education important_commute
# 1 45000 1 AB 1 13
# 2 23465 1 CA 2 32
# 3 89522 2 GA 3 1
我的问题:
tmp
# Error: object 'tmp' not found
names(df1) %<>% inset(tmp<-!grepl("_",.),paste0("important_",.)[tmp]) %>% {tmp}
# Error in function_list[[k]](value) : object 'tmp' not found
我不完全理解环境与magrittr
的工作方式,我很惊喜地看到,tmp
不污染我的工作区,但它是一个安全的实践 ?我实际存储tmp
某处它浪费内存的地方吗?
如果不是,可能是管用的夜晚招!