RWEP/SD/20240321_9_课后作业/第6次课后作业_模板.qmd

43 lines
1.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: 课后作业6
author: 姓名
format: html
---
# 示例问题在R中输出`1+2+3+...+100`的结果
采用`for`循环完成,代码如下:
```{r}
total <- 0
for (i in 1:100) {
total <- total + i
}
total
```
# 如何在 R 中将数字 10 赋值给变量 x
# 在 R 中,如何创建一个包含数字 1 到 5 的向量?
# 编写一个条件语句,如果变量 age 大于等于 18则打印 "成年人",否则打印 "未成年人"。
# 使用 for 循环打印从 1 到 10 的整数。
# 编写一个名为 addition 的函数,接受两个参数 a 和 b返回它们的和。
# 创建一个列表,包含三个元素:一个数字向量、一个字符向量和一个逻辑向量。
# 使用 read.csv() 函数读取名为 data.csv 的 CSV 文件,并将数据存储在一个名为 data 的数据框中。
# 从数据框中选择前五行,并将结果存储在一个新的数据框中。
# 将字符串 "hello world" 转换为大写。
# 从数据框中选择 score 列大于等于 90 的行。