3

在python中可以分解一个列表

x=[1,2,3]
a,b,c=x # a=1 b=2 c=3

是否可以在 R 中做类似的事情?例如:

x=matrix(rnorm(100),10,10)
[u d v]=svd(x)       # instead of u=svd$u d=svd$d  v=svd$v
4

1 回答 1

0

Not without some hackery and fiddly global assignment, and my personal opinion is that this is not a good thing to do.

Why? Well, if the results from svd (to use your example) are returned together there's a good reason they are returned together - they belong together. Once you break it up you lose that relationship. The only win is having fewer characters to type, and that's not one of the things we optimise with programming - readability should win over that.

于 2013-10-31T12:31:12.143 回答