1

I'm using R Version 3.6.1 with the following packages:

library(data.table)
library(haven)
library(psych)
library(dplyr)
library(stringr)
library(xtable)
library(ggplot2)
library(stats)
library(car)
library(pander)
library(lm.beta)
library(lavaan)

My code looks somewhat like this:

dat <- as.data.frame(read_spss("w"))
d<-as.data.frame(subset(dat,select = c("q","r","s","t","u","x","y","z")))

d$x<-recode(d$x, "1='J';2='M'") 

nvalid <- function(x) sum(!is.na(x)) 

d$a<-apply(as.matrix(d[c("q","r","s")]), 1, mean, na.rm = TRUE) 
d$counts <- apply(as.matrix(d[c"q","r","s")]), 1, nvalid) 
d$a<-ifelse(d$counts>=6,d$a,NA) 

d$d<-as.numeric(scale(d$t))
d$e<-as.numeric(scale(d$y))
d$f<-as.numeric(scale(d$z))

d$g<-apply(as.matrix(d$d,d$e,d$f), 1, mean, na.rm = TRUE)
d$counts<-apply(as.matrix($d,d$e,d$f), 1, nvalid)
d$g<-ifelse(d$counts>=1,d$g,NA)

d$h<-recode(d$u, "1='N';2='M'")

rm(nvalid)

d<-subset(d,select=c("a","b","c","x", "y", "z"),
                          !is.na(d$x) &
                          !is.na(d$y) &
                          !is.na(d$z))

For the second "subset"-call I'm getting the well-known error "Error: x and labels must be same type". I already read in several threads that it might have something to do with the order of packages and the label-function/ the S3 method of the haven package conflicting with other packages (Hmisc and others). However, I was not able to find a good workaround or even a fix for the problem. Also...I can't run several basic analysis like lm or even rcorr anymore and keep getting this error.

I would be very happy if someone could help me out with a hint how to solve that problem. Thanks in advance.

Jan
  • 87
  • 1
  • 6

0 Answers0