R语言作业,求问代码怎么写
1)
set.seed(1)
n = 5000
gender = sample(c("f","m"),size = n, TRUE)
dechot = function(gender, type){
n = length(gender)
list = c(NA,n)
for (i in 1:n){
list[i] = switch(gender[i], "f"=type[1], "m"=type[2])
}
return(list)
}
type = c(0,1)
dechot(gender, type)
2)
set.seed(1)
n = 100000
A = floor(runif(n,0,n))
search = function(vector){
n = length(vector)
two = three = number = NA
for (i in 1:n){
if (vector[i]%%2 == 0)
two = rbind(two,vector[i])
if(vector[i]%%3 == 0)
three = rbind(three,vector[i])
}
two.new = two[-1]
three.new = three[-1]
n.two = length(two.new)
n.three = length(three.new)
n.six = length(two.new[two.new%%6 == 0])
number = n.two +n.three-n.six
return(list(c(two.new=two.new, three.new=three.new, number = number)))
}
result = search(A)
result$two.new
result$three.new
result$number
ENSG00000000003.13
ENSG00000000005.5
ENSG00000000419.11
ENSG00000000457.12
ENSG00000000460.15
ENSG00000000938.11
提示:
第一步:删除已存在变量和使用命令( stringsAsFactors = FALSE )以防止出错(R often uses a concept of factors to re-encode strings. This can be too early and too aggressive. Sometimes a string is just a string.To avoid problems delay re-encoding of strings by using stringsAsFactors = FALSE when creating data.frames.)
第二步:导入数据:
e1<-read.table("clipboard",header=T,sep=',')#读取剪切板的内容即其他地方复制后,直接使用该命令调取复制的内容。
或者直接新建.txt文档,将内容复制进去:
了解一下这个包的作用 >?org.Hs.eg.db
发现我们已有的信息ensembl_id,并且得知symbol(对象)这一列表示的是基因名,由此确定答题方向, 通过ensembl_id确定gene_id,再通过gene_id确定基因名 。
我们在g2e和我们已知的数据a的ensembl_id不一样,区别在于最后的版本号,我们已有数据有版本号,而得到的g2e没有版本号,所以先将其版本号去掉。
x,y:用于合并的两个数据框
by,by.x,by.y:指定依据哪些行合并数据框,默认值为相同列名的列.
all,all.x,all.y:指定x和y的行是否应该全在输出文件.
sort: by指定的列是否要排序.
suffixes: 指定除by外相同列名的后缀.
incomparables: 指定by中哪些单元不进行合并.
答案为:
在最后合并两个表格除了使用merge函数,还可以使用match函数
中间的失误:
提示:使用 http://www.cbioportal.org/index.do 定位数据集: http://www.cbioportal.org/datasets
打开 http://www.cbioportal.org/ ,操作如下:
得到另一种形式的图片,但是与网页制作的图片是一致的。
提示使用: http://www.oncolnc.org/
打开提示网址:
画出和网页一致的图(图片还需进一步查资料了解)
生存分析的基本了解: http://wemedia.ifeng.com/81829327/wemedia.shtml
如果 p 值小于阈值(0.05 或 0.01),则两组生存时间有显著差异。