首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >帮助查找向量的下限和上限

帮助查找向量的下限和上限
EN

Stack Overflow用户
提问于 2021-04-13 07:35:28
回答 1查看 69关注 0票数 0

我已经创建了月份和月份数字的向量,然后是6-9个月的向量,然后从那里开始,平均值...

代码语言:javascript
复制
mean(Summer)
Months[mean(Summmer)]

七月

现在我必须使用地板和天花板函数来返回平均夏季月份的月份上限和下限。我认为我是在正确的轨道上,但我得到了错误!有什么想法?

代码语言:javascript
复制
months[x]
months[floor(x)] # July
months[ceiling(x)] # August
EN

回答 1

Stack Overflow用户

发布于 2021-04-13 07:51:45

不太清楚你在做什么,但我尽了最大的努力来给出一个有效的响应示例:

代码语言:javascript
复制
# This is built into R and it gives month names
month.name

# Let's make seasons:
Spring = 3:5
Summer = 6:8
Autumn = 9:11
Winter = c(12,1,2)

# If each season has 3 months, then we can get out a particular monh like so:
month.name[Summer[1]]
month.name[Summer[2]]
month.name[Summer[3]]

# We can also use the min, mean, and max technique for summer:
month.name[min(Summer)]
month.name[mean(Summer)]
month.name[max(Summer)]

# But it doesn't really work for Winter:
month.name[min(Winter)]
month.name[mean(Winter)]
month.name[max(Winter)]

我的猜测是,这里的主要混淆是围绕floor的功能。Floor接受一个向量作为输入,并输出一个将floor函数(向下舍入为最接近的整数)应用于向量的每个元素的向量,因此floor(c(1,2,3))将返回c(1,2,3)floor(1.3)将返回1。天花板的工作原理与此类似。

希望这对你正在尝试做的任何事情都有帮助。通常,提供一个可重现的示例很有帮助,这样其他人就可以运行与您正在运行的代码完全相同的代码,并帮助调试您的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67066922

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档