Out of curiosity: I thought it was possible to use sum() to create a new variable in an R dataframe- the objective being calculating an overall score out of several single values. However sum() apparently sums all the values in a column and not just the values of a single case. What is the mechanism behind this and is there a function that adds the values as the simple addition does?
Daten <- data.frame(
cases = c("first", "second", "third"),
values1= c(1,2,3),
values2= c(27,19,34),
values3= c(2,8,7)
)
Daten$valcomb = sum(Daten$values1,Daten$values2,Daten$values3)
Daten$valcomb2 = Daten$values1+Daten$values2+Daten$values3
print(Daten)
Output
cases values1 values2 values3 valcomb valcomb2
1 first 1 27 2 103 30
2 second 2 19 8 103 29
3 third 3 34 7 103 44
help("sum")?