0
fun1 <- function(x){
  selectDay <- subset(tips, day == x, select = tip)
  print("Day Selected = ")
  print(x)
  meanOfDay <- mean(selectDay)
  meanOfDay
}

fun1("Sun")

In the dataframe I'm working on has many values in day column ("Sun", "Thurs", etc). I'm selecting one (sunday, for instance) and calculating average tips received that day. however, I'm getting an error that says argument is not numeric or logical: returning NA.

How would I solve this? Thank you!

Jaap
  • 81,064
  • 34
  • 182
  • 193
  • 3
    `mean` works on vector. The `selectDay` is still a `data.frame`. You need `mean(selectDay[[1]])` or `mean(unlist(selectDay))` – akrun Jan 06 '18 at 12:53
  • 3
    Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Jan 06 '18 at 12:56
  • Thank you akrun! what does '1' inside the double square brackets actually signify? EDIT: sorry, I just did some primitive tests and I believe its the column number. and my thing only had one column. Solved! – koreankiwitea Jan 06 '18 at 13:01

0 Answers0