I'm working in R with data imported from a csv file and I'm trying to take a rowSum of a subset of my data. The data can either be 0, 1, or blank. I'd like to take a sum of all the 1s across all these rows (and ideally find a count of how many non-blank columns there are in each row, but that's my next problem). I am trying the following code:
df1 <- read.csv("/Users/ardyn/test.csv", header = T, na.strings = "")
rowSums(df1[,36:135])
Which gives me the following error:
"Error in rowSums(df1[, 36:135]) : 'x' must be numeric".
When I check, the columns I'm trying to sum across are factors with 3 levels (".","0","1").
How do I import the data or change my rowSums command so that when I take a sum across a subset of variables it just counts the 1s?