R中的大量变量声明和赋值? [英] Mass variable declaration and assignment in R?
本文介绍了R中的大量变量声明和赋值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
抱歉,如果这是一个愚蠢的问题 - 但这是我第一次尝试使用 R
,最后我写了一些代码:
Apologies if this is a stupid question - but this my first attempt at using R
, and i have ended up writting some code along the lines of:
some <- vector('list', length(files))
thing <- vector('list', length(files))
and <- vector('list', length(files))
another <- vector('list', length(files))
thing <- vector('list', length(files))
在 R
中是否有更好(DRY)的方法来做到这一点?
Is there a nicer (DRY) way to do this in R
?
换言之,我想一次为多个变量分配相同的值(根据@Sven Hohenstein 的回答)
To rephrase, I want to assign the same value to multiple variables at once (as per @Sven Hohenstein's answer)
推荐答案
如果你想一次给多个变量赋值,使用这个:
If you want to assign the same value to multiple variables at once, use this:
some <- thing <- and <- another <- thing <- vector('list', length(files))
这篇关于R中的大量变量声明和赋值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文