When manipulating data, the data may change from numbers to letters. A shortcut to the solution is to occasionally check the data structure with the str command and convert it with the as.integer command.
Another option is to use the “type.convert” command, which recognizes character data as numbers. The type.convert command is characterized by the “na.string” option, which specifies a string of missing values. You can use this command if as.integer returns an error.
Checked with R version 4.2.2.
See the command and package help for details.
#Save numbers as strings ChaTest <- c("1", "2", "3") #Checked Class class(ChaTest)  "character" #Calculation, of course error ChaTest + ChaTest ChaTest + ChaTest error #Calculation, of course error sum(ChaTest) sum(ChaTest) error #Use the "type.convert" command #Detect strings as numbers class(type.convert(ChaTest))  "integer" #Calculation,Get Correct Answer type.convert(ChaTest) + type.convert(ChaTest)  3 #Calculation!! sum(type.convert(ChaTest))  6
I hope this makes your analysis a little easier !!