Simultaneous variable assignment and printing

百般思念 提交于 2019-12-08 16:33:22

问题


I was wondering if there was a way to assign a value and print the value to the console succinctly.

x <- 1:5; x

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


回答1:


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]))


来源:https://stackoverflow.com/questions/22003683/simultaneous-variable-assignment-and-printing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!