我运行此代码并尝试使用dplyr包进行过滤,我收到错误。错误:列' USUBJID'有不支持的类型。我不知道自己做错了什么。
library('SASxport')
library('dplyr')
dm<-read.xport('C:/Temp/SDD/dm.xpt')
filter(dm, SEX=="M")
错误:列&#39; USUBJID&#39;有不支持的类型
我在以下方面遇到了同样的错误:
dplyr::filter(dm, SEX="M")
dm %>% filter(dm, SEX=="M")
以下是该文件的一些元数据:
meta <-select(dm, USUBJID, SEX)
str(meta)
&#39; data.frame&#39;:816 obs。 2个变量:
$ USUBJID:Classes 'labelled', 'character' atomic [1:816] .. ..- attr(*, "label")= chr "Unique Subject Identifier"
$ SEX : Factor w/ 2 levels "F","M": - attr(*, "label")= chr "Sex" - attr(*, "label")= chr " "- attr(*, "SAStype")= chr " "
答案 0 :(得分:2)
使用?read.xport
library(SASxport)
w1 <- w$TEST[1:2]
w1 %>%
filter(RACE=='blue')
#Error: column 'AGE' has unsupported type
str(w1)
#'data.frame': 2 obs. of 2 variables:
#$ RACE: Factor w/ 3 levels "green","blue",..: 2 NA
# .- attr(*, "SASformat")= chr "RACE"
# $ AGE :Classes 'labelled', 'integer' atomic [1:2] 30 31
# .. ..- attr(*, "label")= chr "Age at Beginning of Study"
w1[] <- lapply(w1, function(x) {
attr(x, 'SASformat') <- NULL
attr(x, 'label') <- NULL
x})
class(w1$AGE) <- NULL
w1 %>%
filter(RACE=='blue')
# RACE AGE
#1 blue 30
基于上面的例子,我想是meta
数据
meta[] <- lapply(meta, function(x) {
attr(x, 'SAStype') <- NULL
attr(x, 'label') <- NULL
x})
class(USUBJID) <- NULL
filter(meta, SEX=='M')
testFile <- system.file('extdata', 'test2.xpt', package="SASxport")
w <- read.xport(testFile)