由于字符变量,在R中运行T-Test时出现错误消息

I have been trying to run a two side t-test in R but keep running into error. Below is my process flow, dataset details and script from R-studio. I used a dataset called LungCapacity that I downloaded from this website: https://www.statslectures.com/r-scripts-datasets.

#Imported data set into RStudio.

# Ran a summary report to see the data and class.
summary(LungCapData)

# Here I could see that the smoke column is a character, so I converted it to a factor
LungCapacityData$Smoke <- factor(LungCapacityData$Smoke)

# On checking the summary. I see its converted to a factor with a yes and no.

# I want to run a t-test between lung capacity and smoking. 
t.test(LungCapData$LungCap, LungCapData$Smoke, alternative = c("two.sided"), mu=0, var.equal = FALSE, conf.level = 0.95, paired = FALSE)

现在,在运行它时,我得到以下错误。

Error in var(y) : Calling var(x) on a factor x is defunct.
  Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.
In addition: Warning message:
In mean.default(y) : argument is not numeric or logical: returning NA

我试图将Smoke变量从Yes和No转换为1和0。数据正在运行,但不正确。 我究竟做错了什么?