I'm working through the book: Hands on R programming. The following code is pasted directly from the book but will not run in RStudio and I'm trying to understand why.
system.time(
output <- rep(NA, 1000000) for (i in 1:1000000) {
output[i] <- i + 1
}
)
I get this:
> system.time(
+ output <- rep(NA, 1000000) for (i in 1:1000000) {
Error: unexpected 'for' in:
"system.time(
output <- rep(NA, 1000000) for"
> output[i] <- i + 1
Error: object 'i' not found
> }
Error: unexpected '}' in " }"
> )
Error: unexpected ')' in ")"
Firstly, a missing ;
. Secondly, we need to {}
all the expressions.
system.time({
output <- rep(NA, 100); for (i in 1:100) {
output[i] <- i + 1
}}
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With