前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >生信入门 第五天

生信入门 第五天

原创
作者头像
用户11153857
发布2024-06-12 10:07:00
810
发布2024-06-12 10:07:00
举报

This is my day 5 homework for BIC by 生信星球.

Today's content is the introduction of data structure.

Before study, gain the demo data from wechat public account.

tips:

(1) the assignment symbol for R is <-, which can also be replaced by =. This answers my question in previous study.

(2) console equals command line in Linux

(3) the code in R includes (), which must be English input

(4) getwd() shows the working directory

(5) vector is made up of element which can be number or string

(6) table is called data frame (df) in R

(7) read help document by ?read.table, try example

(8) data type, focus on vector and data frame

1. vector

1.1 vector is a list of items that are of the same type

the associations among variable, item, vector.

代码语言:R
复制
x<- c(1,2,3) 
x<- 1:10  # from 1 to 10 , 10 integers 

1.2 extract items from vetor:

(1) by location

代码语言:R
复制
x[4]  # the 4th item in x
x[-4] # reverse choose, exclude the 4th item in x and include others
x[2:4] #from 2nd to 4th 
x[-(2:4)] # reverse choose
x[c(1,5)] # the 1st and 5th

(2) by value

代码语言:R
复制
x[x==10] # item equals 10 in x
x[x<0] # items less than 0 in x
x[x %in% c(1,2,5)] # items in vector c(1,2,5)

2. data frame

the demo data must be in the working directory

2.1 read local data

代码语言:R
复制
read.table(file = "huahua.txt", sep = "\t", header = T)
a <- read.table(file = "huahua.txt", sep = "\t", header = T)

2.2 check line name, numbers of lines and colunms

代码语言:R
复制
colnames(a)  #check the colunm name
rownames(a) # check the line name
dim(a) #check the structre of data frame

2.3 save data frame

代码语言:R
复制
write.table(a, file = "yu.txt", sep = ",", quote = F)

2.4 save vairables and load variables

代码语言:R
复制
save.image(file="bioinfoplanet.RData") #save current image
save(a,file="test.RData") # save a as test.RData
load("test.RData") # load test.RData

2.5 extract items

by $ symbol

by location of coordinate

代码语言:R
复制
a[x,y] 

by name of colunm

代码语言:R
复制
a[x,]
a[,y]
a[c(a,b)] #a colunm and b colunm

2,6 directly use the variables in data frame

代码语言:R
复制
plot(iris$Sepal.length, iris$Sepal.Width)

save(a,file="test.RData") report: object a not found

check whether the object a is in the right-up section of Rstudio

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1. vector
    • 1.1 vector is a list of items that are of the same type
      • 1.2 extract items from vetor:
      • 2. data frame
        • 2.1 read local data
          • 2.2 check line name, numbers of lines and colunms
            • 2.3 save data frame
              • 2.4 save vairables and load variables
                • 2.5 extract items
                  • 2,6 directly use the variables in data frame
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档