1、学会建立一个表:
> a<-data.frame(GeneId = rep("gene5",times=3),SampleName =paste("Sample",1:3,sep=""),Expression=c(14,18,18))
这上面是代码
分别的意思是:
显示如下:
之后进入正题:
2.按照小抄建一个表格
a<-data.frame(country=c("A","B","C"),"1999"=paste(c(0.7,37,212),"K"),"2000"=paste(c(2,80,213),"K"))
3.之后用gather()
gather(a,X1999,X2000,key="year",value = "cases")
gather(a,year,cases,-country) #如果合并前列数比较多,-country的意思就是合并除country外剩下的列。
PS:报错当做没看见
4.删除空行:
> X<-read.csv('doudou.txt')
> View(X)
> drop_na(X,X2)
X1 X2
1 A 1
4 D 3
5.根据上一行的数据补上:
> fill(X,X2)
X1 X2
1 A 1
2 B 1
3 C 1
4 D 3
5 E 3
6.空的都由自定义的数补上:
> replace_na(X,list(X2=2))
X1 X2
1 A 1
2 B 2
3 C 2
4 D 3
5 E 2
7.complete:
> complete(X,nesting(X1),fill = list(X2=5))
# A tibble: 5 x 2
X1 X2
<fct> <dbl>
1 A 1
2 B 5
3 C 5
4 D 3
5 E 5
8.一种操作?:
> expand(pin2,GeneId,SampleName,Expression)
# A tibble: 9 x 3
GeneId SampleName Expression
<fct> <fct> <dbl>
1 gene5 Sample1 14
2 gene5 Sample1 18
3 gene5 Sample1 19
4 gene5 Sample2 14
5 gene5 Sample2 18
6 gene5 Sample2 19
7 gene5 Sample3 14
8 gene5 Sample3 18
9 gene5 Sample3 19