找回密码
 注册
查看: 4088|回复: 0

R语言:with()函数中文帮助文档(中英文对照)

[复制链接]
发表于 2012-2-16 20:13:43 | 显示全部楼层 |阅读模式
with(base)
with()所属R语言包:base

                                        Evaluate an Expression in a Data Environment
                                         评估数据环境中的表达

                                         译者:生物统计家园网 机器人LoveR

描述----------Description----------

Evaluate an R expression in an environment constructed from data, possibly modifying the original data.
从数据可能修改原始数据,构建了一个环境评估R表达。


用法----------Usage----------


with(data, expr, ...)
within(data, expr, ...)



参数----------Arguments----------

参数:data
data to use for constructing an environment. For the default with method this may be an environment, a list, a data frame, or an integer as in sys.call. For within, it can be a list or a data frame.
数据用于环境建设。对于默认with方法,这可能是一个环境,一个列表,一个数据框,或在sys.call整数。 within,它可以是一个列表或一个数据框。


参数:expr
expression to evaluate.
表达式。


参数:...
arguments to be passed to future methods.
参数被传递给未来的方法。


Details

详情----------Details----------

with is a generic function that evaluates expr in a local environment constructed from data.  The environment has the caller's environment as its parent.  This is useful for simplifying calls to modeling functions.  (Note: if data is already an environment then this is used with its existing parent.)
with是一个通用的函数,计算expr从data在本地环境中构建。环境作为其母公司的呼叫者的环境。简化建模功能的调用,这是有用的。 (注:data如果已经是一个环境,那么这是使用其现有的父。)

Note that assignments within expr take place in the constructed environment and not in the user's workspace.
注意:在expr的任务在构建环境的地方,不是在用户的工作空间。

within is similar, except that it examines the environment after the evaluation of expr and makes the corresponding modifications to data (this may fail in the data frame case if objects are created which cannot be stored in a data frame), and returns it.  within can be used as an alternative to transform.
within类似,只不过它检查后评价expr的环境,并作出相应的修改data(这可能对象的创建失败,如果在数据框的情况下,不能存储在一个数据框),并返回它。 within可以用来作为替代transform。


值----------Value----------

For with, the value of the evaluated expr.  For within, the modified object.
with,价值的评估expr。 within,修改的对象。


参见----------See Also----------

evalq, attach, assign, transform.
evalq,attach,assign,transform。


举例----------Examples----------


require(stats); require(graphics)
#examples from glm:[从GLM的例子:]
## Not run: [#无法运行:]
library(MASS)
with(anorexia, {
    anorex.1 <- glm(Postwt ~ Prewt + Treat + offset(Prewt),
                    family = gaussian)
    summary(anorex.1)
})

## End(Not run)[#结束(不运行)]



aq &lt;- within(airquality, {     # Notice that multiple vars can be changed[注意多个瓦尔可以改变的]
    lOzone<-log(Ozone)
    Month<-factor(month.abb[Month])
    cTemp &lt;- round((Temp - 32) * 5/9, 1) # From Fahrenheit to Celsius[从华氏温度为摄氏]
    rm(Day, Temp)
})
head(aq)

with(data.frame(u = c(5,10,15,20,30,40,60,80,100),
                lot1 = c(118,58,42,35,27,25,21,19,18),
                lot2 = c(69,35,26,21,18,16,13,12,12)),
    list(summary(glm(lot1 ~ log(u), family = Gamma)),
         summary(glm(lot2 ~ log(u), family = Gamma))))

# example from boxplot:[例如从盒形图:]
with(ToothGrowth, {
    boxplot(len ~ dose, boxwex = 0.25, at = 1:3 - 0.2,
            subset = (supp == "VC"), col = "yellow",
            main = "Guinea Pigs' Tooth Growth",
            xlab = "Vitamin C dose mg",
            ylab = "tooth length", ylim = c(0,35))
    boxplot(len ~ dose, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2,
            subset = supp == "OJ", col = "orange")
    legend(2, 9, c("Ascorbic acid", "Orange juice"),
           fill = c("yellow", "orange"))
})

# alternate form that avoids subset argument:[另一种形式,避免子集参数:]
with(subset(ToothGrowth, supp == "VC"),
     boxplot(len ~ dose, boxwex = 0.25, at = 1:3 - 0.2,
             col = "yellow", main = "Guinea Pigs' Tooth Growth",
             xlab = "Vitamin C dose mg",
             ylab = "tooth length", ylim = c(0,35)))
with(subset(ToothGrowth,  supp == "OJ"),
     boxplot(len ~ dose, add = TRUE, boxwex = 0.25, at = 1:3 + 0.2,
             col = "orange"))
legend(2, 9, c("Ascorbic acid", "Orange juice"),
       fill = c("yellow", "orange"))

转载请注明:出自 生物统计家园网(http://www.biostatistic.net)。


注:
注1:为了方便大家学习,本文档为生物统计家园网机器人LoveR翻译而成,仅供个人R语言学习参考使用,生物统计家园保留版权。
注2:由于是机器人自动翻译,难免有不准确之处,使用时仔细对照中、英文内容进行反复理解,可以帮助R语言的学习。
注3:如遇到不准确之处,请在本贴的后面进行回帖,我们会逐渐进行修订。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|生物统计家园 网站价格

GMT+8, 2025-1-24 13:23 , Processed in 0.019259 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表