删除附带外部/ Hmisc SPSS导入功能的变量标签 [英] Remove variable labels attached with foreign/Hmisc SPSS import functions

查看:139
本文介绍了删除附带外部/ Hmisc SPSS导入功能的变量标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像往常一样,我从 Hmisc spss.get 函数>包裹。我对标记为的类感到困扰, Hmisc :: spss.get 添加到 data.frame ,因此想删除它。

As usual, I got some SPSS file that I've imported into R with spss.get function from Hmisc package. I'm bothered with labelled class that Hmisc::spss.get adds to all variables in data.frame, hence want to remove it.

标记为 class给了我当我尝试运行 ggplot 时,或者甚至当我想做一些卑鄙的分析时,我很头疼!一种解决方案是从 data.frame 中的每个变量中删除标记为的类。我怎样才能做到这一点?这有可能吗?如果没有,我的其他选择是什么?

labelled class gives me headaches when I try to run ggplot or even when I want to do some menial analysis! One solution would be to remove labelled class from each variable in data.frame. How can I do that? Is that possible at all? If not, what are my other options?

我真的想借用 as.data.frame(lapply)从头开始绕过重新编辑变量x,as.numeric)) as.character 适用的地方......我当然不想运行SPSS并手动删除标签(不喜欢SPSS,也不关心安装它)!

I really want to bypass reediting variables "from scratch" with as.data.frame(lapply(x, as.numeric)) and as.character where applicable... And I certainly don't want to run SPSS and remove labels manually (don't like SPSS, nor care to install it)!

谢谢!

推荐答案

您可以避免在spss.get中使用参数创建已标记变量:,use.value.labels = FALSE。

You can avoid creating "labelled" variables in spss.get with the argument: , use.value.labels=FALSE.

w <- spss.get('/tmp/my.sav', use.value.labels=FALSE, datevars=c('birthdate','deathdate'))

如果标签载体的类别只是标记而不是c(标记,因子,Bhattacharya的代码可能会失败)在这种情况下应该是:

The code from Bhattacharya could fail if the class of the labelled vector were simply "labelled" rather than c("labelled", "factor") in which case it should have been:

class(x[[i]]) <- NULL  # no error from assignment of empty vector

您报告的错误可能是转载此代码:

The error you report can be reproduced with this code:

> b <- 4:6
> label(b) <- 'B Label'
> str(b)
Class 'labelled'  atomic [1:3] 4 5 6
  ..- attr(*, "label")= chr "B Label"
> class(b) <- class(b)[-1]
Error in class(b) <- class(b)[-1] : 
  invalid replacement object to be a class string

这篇关于删除附带外部/ Hmisc SPSS导入功能的变量标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆