当前位置: 首页 > news >正文

R study notes[1]

文章目录

  • introducing to R
  • references

introducing to R

  1. R is an integrated suite involved data handling,storage facility,calculations on arrays,tools for data analysis and so on.
  2. running the command R in the terminal of OS can start R software.in R terminal ,to input q() can quit R software.
  3. the R source codes can bet puted together into a file,assuming the name is “source.R”, follow with running by source("source.R") in R terminal.
  4. objects() is a R command to show all objects created by the R session survived . call rm() for delete a part of these objects.

在这里插入图片描述

> rm(x)
> objects()
[1] "y"
  1. make a vector is simple,for example, to run the code x<-c(1,2,3,4,5,6,7,4,3,5,8).seq used to generate a sequence like arrange in python.
> x<-c(1,2,3,4,5,6,7,4,3,5,8)
> y<-seq(1,8,0.2)
> x[1] 1 2 3 4 5 6 7 4 3 5 8
> y[1] 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 2.8 3.0 3.2 3.4 3.6 3.8 4.0 4.2 4.4 4.6 4.8 5.0 5.2 5.4 5.6 5.8 6.0 6.2 6.4 6.6 6.8 7.0 7.2 7.4 7.6 7.8 8.0
> 
  1. arrange function in R is used for sorting a data frame by one or more variables,must install the package called as dplyr installed with install.packages("dplyr").
> mtcarsmpg cyl  disp  hp drat    wt  qsec vs am gear carb
Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4
Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1
Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1
Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4
Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2
Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4
Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3
Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3
Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3
Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4
Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4
Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1
Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2
Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1
Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2
AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2
Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4
Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2
Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2
Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2
> arranged_data <- arrange(mtcars, mpg)
> head(arranged_data)mpg cyl disp  hp drat    wt  qsec vs am gear carb
Cadillac Fleetwood  10.4   8  472 205 2.93 5.250 17.98  0  0    3    4
Lincoln Continental 10.4   8  460 215 3.00 5.424 17.82  0  0    3    4
Camaro Z28          13.3   8  350 245 3.73 3.840 15.41  0  0    3    4
Duster 360          14.3   8  360 245 3.21 3.570 15.84  0  0    3    4
Chrysler Imperial   14.7   8  440 230 3.23 5.345 17.42  0  0    3    4
Maserati Bora       15.0   8  301 335 3.54 3.570 14.60  0  1    5    8
  1. many of compuations can be applied to vector as follows.
> x[1]  1  2  4  2  5  4  3  4  1  4 55 22
> x*8-2[1]   6  14  30  14  38  30  22  30   6  30 438 174> arranged_data$wt*2[1] 10.500 10.848  7.680  7.140 10.690  7.140  7.560  6.870  7.040  6.340  8.140  7.460  6.880  6.920  6.880  6.880  7.690  5.540  5.240  5.750  6.430  5.560  4.930
[24]  4.640  6.300  6.380  4.280  3.870  3.230  3.026  4.400  3.670

references

  1. https://www.r-project.org/
http://www.dtcms.com/a/296389.html

相关文章:

  • linux入门 相关linux系统操作命令(二)--文件管理系统 ubuntu22.04
  • 二分查找-153-寻找旋转排序数组中的最小值-力扣(LeetCode)
  • unordered_map和unordered_set特性以及解决哈希冲突
  • Gemini拿下IMO2025金牌的提示词解析
  • Redis Lua脚本语法详解
  • Redis ①⑦-分布式锁
  • 跨模态理解的基石:非文本内容向量化方法全景解析
  • Lua协同程序(coroutine)
  • leetcode100.相同的树(递归练习题)
  • Xilinx-FPGA-PCIe-XDMA 驱动内核兼容性问题修复方案
  • 基于单片机睡眠质量/睡眠枕头设计
  • 1.1.2 建筑构造要求
  • 无人机正摄影像自动识别与矢量提取系统
  • 用phpEnv安装Thinkphp8.x出错调试全过程记录
  • C++ 中打开文件的多种方式及相关流类
  • matplotlib的详细知识点
  • k8s之ingress定义https访问方式
  • 【AI News | 20250723】每日AI进展
  • Windows11 本地安装docker Desktop 部署dify 拉取镜像报错
  • iOS Core Data 本地数据库 使用详解:从模型关系到数据操作
  • 技嘉z370主板开启vtx
  • 谈谈ArrayList与Vector的理解?
  • SpringBoot+AI+Web3实战指南
  • Python循环结构
  • 红黑树:高效平衡的终极指南
  • c语言学习(dyas10)
  • Kubernetes Kubelet 资源配置优化指南:从命令行参数到配置文件的最佳实践
  • Spring AI - ChatModel接口演示
  • TCO,UDP考点
  • 开发避坑短篇(5):vue el-date-picker 设置默认开始结束时间