英文:
Can I change dataframe column label in a pipe using base R?
问题
我想做类似的事情:
df %>%
`attr<-`(.$column, "label", NULL)
以删除数据框列的标签,而无需加载外部包只为执行此特定操作(例如,labelled、sjlabelled)。是否可能?
英文:
I want to do something like:
df %>%
`attr<-`(.$column, "label", NULL)
To remove the label of a dataframe column, without having to load an external package just to perform this specific action (e.g. labelled, sjlabelled). Is it possible?
答案1
得分: 1
感谢 @Ritchie Sacramento 在评论中提供的答案:
选项 1(基于基础 R):
df |> transform(column = `attr<-`(column, "label", NULL))
选项 2(需要 magrittr):
df %>% {attr(.$column, "label") <- NULL; .}
英文:
Thanks to @Ritchie Sacramento for answers in the comments:
Option 1 (base R):
df |> transform(column = `attr<-`(column, "label", NULL))
Option 2 (requires magrittr):
df %>% {attr(.$column, "label") <- NULL; .}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论