Im tryin to make a simple function where I have three possible arguments ("sun", "rain" or "wind") and the function should return the three months mean of chosen one.
rows <- c("april", "may", "june")
sun <- c(11,13,18)
rain <- c(8,7,5)
wind <- c(11,8,4)
table <- data.frame(sun=sun, rain=rain,wind=wind, row.names=rows)
function(argument){
sun <- table$sun
rain <- table$rain
wind <- table$wind
x <- mean(argument)
paste(x)
}
For example function("sun") should return 14.
The problem is that I understand how to link the argument to the column that includes the values.