较长的物体长度不是较短物体长度的倍数 [英] longer object length is not a multiple of shorter object length

查看:32
本文介绍了较长的物体长度不是较短物体长度的倍数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R 环境的真正新手,我正在阅读R 简介"一书.

A Real newbie to R environment, I am going through the book "Introduction to R".

在一个例子中,作者建议

There, in an example, author suggests that "

表达式中较短的向量会根据需要循环使用(也许是小数)直到它们匹配最长的长度矢量.

Shorter vectors in the expression are recycled as often as need be (perhaps fractionally) until they match the length of the longest vector.

紧接着,有这个例子......其中它表明一个向量将重复2.2次......

Immediately after that, there is this example... wherein it suggests that a vector would be repeated 2.2 times...

但是,当我在我的系统(ubuntu 64b,R - v2.4.11)上复制相同的示例时,我收到此错误消息

However, when I replicated the same example on my system (ubuntu 64b, R - v2.4.11), I got this error message

x
[1]  2  5  8  6 11
> y
[1] 23 11
> v=2*x+y+1
Warning message:
In 2 * x + y :
  longer object length is not a multiple of shorter object length
> v
[1] 28 22 40 24 46

尝试在内部搜索 google、stackoverflow,但找不到任何令人满意的东西...我在这里遗漏了什么吗?我使用的 R 版本有什么问题吗?

Tried searching through google, stackoverflow internally as well, but couldnt find anything satisfactory... Am I missing something here ? is there something with the version of R I am using ?

推荐答案

当一个 vector 被回收时,如果它在完成之前必须被切断",它会显示一条警告消息.(如下所述,这不是错误消息.Error = R 无法完成您想要的功能,因此它退出.Warning = R 找到了一些东西奇怪的是你要求它做什么但仍然可以做到.*)

When a vector is recycled, it will display a warning message if it has to be "cut off" before it's finished. (as mentioned below, an this is NOT an error message. Error = R can't complete the function you want it to and so it quits. Warning = R found something strange about what you're asking it to do but can still do it.*)

例如:

c(1,2) * c(1,2,3,4)

相当于:

c(1,2,1,2) * c(1,2,3,4)

并且不显示警告消息.但是:

And displays no warning message. But:

c(1,2) * c(1,2,3,4,5)

相当于:

c(1,2,1,2,1) * c(1,2,3,4,5)

并显示警告消息,因为强制向量的最后一个元素不是原始向量中的最后一个元素.它仍然会完成工作并给你一个答案.警告只是警告.参见 ?warning.

And displays a warning message, since the last element of the coerced vector is not the last element in the original vector. It will still do the work and give you an answer. The warning is just a warning. See ?warning.

* 参见 的第 2 节这篇论文

这篇关于较长的物体长度不是较短物体长度的倍数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆