curly brackets and function x
Closed this issue · 2 comments
Hi Andrew,
I know this is very basic question but I'm just confused between brackets you used in steps 11 and 12... could we use just square brackets or we need to use different brackets like we use in mathematics in order to subset any statement.
also what does x mean when we say function(x) like in case of (i) we create index for different species..
I'm sorry if I miss any point in understanding them.
Thank you!
Best,
Uz
Great questions! The square brackets in R index elements of a vector; the curly brackets surround a statement and indicate to R that it should be interpreted as a unit (e.g., in a loop or function).
If you define a function, you do so with arguments of arbitrary (but R-legal) names. If you create:
add_and_print <- function(x) print(as.numeric(sum(x)))
x
is simply the argument passed into the function. It could as easily have been i
or y
or pony
.
Does this answer your questions?
thanks,
Andrew
yes..Thank you!
Best,
Uz