2013-04-25 53 views
1

在包nnet,下面的例子说明:R中公式参数的语法是什么?

# or 
ird <- data.frame(rbind(iris3[,,1], iris3[,,2], iris3[,,3]), 
     species = factor(c(rep("s",50), rep("c", 50), rep("v", 50)))) 
ir.nn2 <- nnet(species ~ ., data = ird, subset = samp, size = 2, rang = 0.1, 
       decay = 5e-4, maxit = 200) 
table(ird$species[-samp], predict(ir.nn2, ird[-samp,], type = "class")) 

我不明白,这部分是如何工作的:species ~ .,我的理解是某种公式是作为参数传递,但我不知道在哪里搜索关于配方语法的更多信息以及.将代表什么。

请关闭此问题,如果它是重复的,我找不到相同的问题。

+0

'.'代表所有其余特征(列) – Nishanth 2013-04-25 16:13:14

+0

做你想添加一个完整的答案来解释R中公式的语法是什么? – BlueTrin 2013-04-25 16:28:02

回答

2

.代表除结果(写在~的RHS上)之外的所有特征/列。更多信息可以在这里?formula

基本上可以发现,对于iris3数据组,式

species ~ . 

相当于

species ~ Sepal L. + Sepal W. + Petal L. + Petal W.