在R中,如何查找整数是否可以被数字整除? [英] In R how do I find whether an integer is divisible by a number?
本文介绍了在R中,如何查找整数是否可以被数字整除?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
很抱歉,我是R的入门程序员 例如: 如果我偶然遇到一个FOR循环,并且我有一个整数1到100(1:100)的集合,那么什么是正确的格式以确保可以打印出可以被另一个数字整除的数字.在这种情况下,5是可整除的数字.我听说在这种情况下使用取模将有助于%%
Sorry for the inexperience, I'm a beginning coder in R For example: If I were to make a FOR loop by chance and I have a collection of integers 1 to 100 (1:100), what would be the proper format to ensure that would print the numbers that are divisible by another number. In this case, 5 being the number divisible. I hear that using modulo would help in this instance %%
这就是我应该拥有的.
For (x in 1:100) {
x%%5 == y
}
print(y)
推荐答案
for (x in 1:100) {
if (x%%5 == 0) {
print(x)
}
}
这篇关于在R中,如何查找整数是否可以被数字整除?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文