Closed brubinoff closed 7 years ago
I am confused about the same thing! @ryanpeek
Let's go over it in class. But for the record, essentially whenever you run a command or send it to your console, the output for direct calculator type functions is the same as when wrapped in print.
Example:
4+4
is shown as 8
, and print(4+4)
will also be 8
.
print
becomes helpful when you assign an object using the <-
, sometimes you can assign something and it won't display the outcome in your console. To see this object, you would need to type that name, or wrap it in paranthesis. Print can be useful for things like plots, or more complicated function outputs that you are saving (or assigning) to your environment.
vector_of_numbers <- c(10, 20, 30, 40)
# This outputs nothing, but you'll see it in your Environment tabprint(vector_of_numbers)
# prints the object(vector_of_numbers <- c(10, 20, 30, 40)
# wrapping in parentheses will also print the output of something
I'm confused as to what the print() function does. If you run the code (for example, 10-2 vs print(10-2)) it returns the exact same output. Why use this function?
Thanks!
Ben