[R] cat() and print()
2018-07-31 本文已影响0人
木木资料馆
An essential difference between cat and print is the class of the object they return. This difference has practical consequences for what you can do with the returned object.
print returns a character vector:
> print(paste("a", 100* 1:3))
"a 100" "a 200" "a 300"
> class(print(paste("a", 100* 1:3)))
"a 100" "a 200" "a 300"
"character"
cat returns an object of class NULL:
> cat(paste("a", 100* 1:3))
a 100 a 200 a 300
> class(cat(paste("a", 100* 1:3)))
a 100 a 200 a 300
"NULL"