美文网首页
R语言练习小代码【一】

R语言练习小代码【一】

作者: Bio_Infor | 来源:发表于2022-04-21 21:53 被阅读0次

Question

Description
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Finish the solution so that it returns the sum of all the multiples of 3 or 5 below the number passed in. Additionally, if the number is negative, return 0 (for languages that do have them).
Note: If the number is a multiple of both 3 and 5, only count it once.

Example

solution <- function(number){
  ...
}

solution(10)
> 23
solution(20)
> 78

Solution to question

solution <- function(number){
  x = seq(1,number-1)
  return(sum(x[x%%3==0 | x%%5==0]))
}

相关文章

  • R语言练习小代码【一】

    Question Description:If we list all the natural numbers b...

  • Day2-R

    sthda R作图代码大全生信人20个R语言练习题一份精美答案 提纲: R数据结构 tidyverse, tid...

  • 【生信技能树】R语言中级练习题

    R语言小作业-中级代码来自Jimmy的Github 所以更多的精力是理解注释代码。 根据R包org.Hs.eg.d...

  • 归零——前端学习-html-第一天

    (小细节决定成败) hyperText markup language——html 超文本标记语言 练习 练习代码

  • R、LINUX、RNA-seq习题

    R语言的练习题初级10 个题目,尽量根据参考代码理解及完成:http://www.bio-info-trainee...

  • 学习小组Day4笔记--大水

    R语言基础 0.1什么是R语言? R是用于统计、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开...

  • 2020.2.1 R语言|Practice1

    一、Day1今天的学习任务: 1.R语言的基础语法检验 2.统计可视化代码练习 3.Jimmy生信技能树B站R系列...

  • R语言介绍与散点图绘制

    R语言简介 什么是R语言 R是用于统计分析、绘图的语言和操作环境。R是属于GNU系统的一个自由、免费、源代码开放的...

  • R语言代码规范

    编程的代码规范目的是使我们的R代码更容易阅读、分享和验证,下述是一些约定俗成的代码规范: 1.0 文件名 对于R ...

  • R|来自 Google 的 R 语言编码风格指南

    R 语言是一门主要用于统计计算和绘图的高级编程语言. 这份 R 语言编码风格指南旨在让我们的 R 代码更容易阅读、...

网友评论

      本文标题:R语言练习小代码【一】

      本文链接:https://www.haomeiwen.com/subject/rjwpdrtx.html