I'm having trouble subsetting my data to delete excluded participants. The variable excluded is coded such that yes = 1 (i.e., exclude), and no = 0 (i.e., include). Data was imported from REDCap using the REDCap script. Here's what I've tried, with the error being written above the syntax that isn't working:
#this resulted in 0 rows
df2<-subset(df, df1$excluded == 0)
#this produced the error message Error in `[.data.frame`(df1, df1$excluded == : undefined columns selected
df2 <-df1[df1$excluded == 0]
#This deleted all data in the dataframe
df2<-df1[!(df1$excluded == 1),]
#this resulted in 0 rows
df2<-subset(df1, df1$excluded !=1)
#this resulted in 0 rows
df2<-subset(df1, df1$excluded !="1")
#this resulted in the subset selecting excluded participants instead of included participants
df2<-subset(df1, df1$excluded.factor !="yes")
Here are the variable types:
class(df1$excluded) [1] "labelled" "integer"
class(participantdata.df$excluded.factor) [1] "factor"
Any idea why this is happening and how to fix it?
Thanks!