Simultaneous variable assignment and printing in R

2019-06-20 08:30发布

Sorry if may be a trivial question, but I was wondering if there was a way to assign a value and print the value to the console succinctly.

x <- 1:5; x

Is how I would presently do this, but I was wondering if there was a way to do it in one statement. Thanks!

1条回答
霸刀☆藐视天下
2楼-- · 2019-06-20 09:05

You can try:

(x <- 1:5)

or

print(x <- 1:5)

though that won't work for things like

(names(x) <- letters[1:5])

though for that specific example you can do:

(x <- setNames(x, letters[1:5]))
查看更多
登录 后发表回答