小编Mag*_*nus的帖子

R中的function()-函数是否“不需要”需要大括号?

我最近在R教程中遇到了以下示例:

sapply(list(runif (10), runif (10)), 
   function(x) c(min = min(x), mean = mean(x), max = max(x))
Run Code Online (Sandbox Code Playgroud)

我的印象是,在function() -function中,您首先必须在括号内列出参数,然后在大括号内列出该函数执行的操作。

In this example there are "no" curly brackets and the code seems to function anyway, how can this be?

syntax r function

5
推荐指数
1
解决办法
88
查看次数

R 中的 print() 和 print(paste()) 函数有什么区别?

正如标题所述。

我正在自己学习 Datacamp R 教程,但我发现缺乏说明。

更令人恼火的疏忽之一是许多基本函数从未定义或解释,其中包括 print() 和 Paste() 函数。有时我可以使用其中一种,有时可以使用另一种,现在这对我来说似乎完全是随机的。

我在互联网上搜索了一个明确的答案,但没有找到答案。

我将重申我的问题:

什么时候可以使用 print() 函数,什么时候必须在括号中插入粘贴函数 print(paste())?

r

2
推荐指数
1
解决办法
1583
查看次数

我可以用正则表达式创建向量吗?

我的数据看起来像这样:

412 U CA, Riverside
413 U British Columbia
414 CREI
415 U Pompeu Fabra
416 Office of the Comptroller of the Currency, US Department of the Treasury
417 Bureau of Economics, US Federal Trade Commission
418 U Carlos III de Madrid
419 U Brescia
420 LUISS Guido Carli
421 U Alicante
422 Harvard Society of Fellows
423 Toulouse School of Economics
424 Decision Economics Inc, Boston, MA
425 ECARES, Free U Brussels
Run Code Online (Sandbox Code Playgroud)

我将需要对这些数据进行地理编码,以获取每个特定机构的坐标。为了做到这一点,我需要阐明所有州名。同时,我不希望将“ ECARES”之类的缩写转换为“ ECaliforniaRES”。

我一直在想将state.abb和state.name向量转换为正则表达式的向量,所以state.abb看起来像这样(使用阿拉巴马州和加利福尼亚州作为状态1和状态2):

c("^AL "|" AL …
Run Code Online (Sandbox Code Playgroud)

regex r vector

2
推荐指数
1
解决办法
40
查看次数

标签 统计

r ×3

function ×1

regex ×1

syntax ×1

vector ×1