1

I'd like to use loop (addition clause) to calculate the total number of casual renters (NOT data/observation) IF the season= 1 (season Spring). However, we are stuck with this problem.

Here is our code:

SpringCasualRenter <-rep(0,17379) for(i in 1:17379) { if(allData$season ==1 & allData$Casual.renter & i++) print(i)}

Total observations: 17379. #

Season: Spring 1, Summer 2, Autumn 3, Winter 4

Casual renter - number of non-registered user rentals initiated. Registered renter - number of registered user rentals initiated

Thank you in advance!

Jaap
  • 81,064
  • 34
  • 182
  • 193
Mary Jones
  • 11
  • 2
  • Welcome to StackOverflow! 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 Feb 17 '16 at 10:31
  • Hmm, there are several language-related mistakes here... For example, in R you don't use `i++`. You may want to read up on how `for`-loops work. – slamballais Feb 17 '16 at 10:41
  • @Laterow Alright, thank you for the tip! Any idea what should we replace "i++" with? – Mary Jones Feb 17 '16 at 10:52
  • With.. nothing? Currently it is in the `if` clause, so you are testing if `i++` is true, but given that `i++` doesn't mean anything in R, it will throw an error (probably about an unexpected `)` ). Again, I'd highly recommend just reading up on `for`-loops in R, since it seems to me that you are used to a different language and you might as well read up on `for`-loops properly. – slamballais Feb 17 '16 at 11:02

0 Answers0