整理一下今天按照培训R语言时候的教程报过的错
1.建立数据框
建立如图的数据框
报错的代码:
df = data.frame(gene = paste0("gene",1:15),
+ s1 = rnorm(15),
+ s2 = rnorm(15),
+ s3 = rnorm(15),)
仔细看一下,,,,然后再展示报错内容。。
5
4
3
2
1
Error: unexpected '=' in:"df = data.frame(gene = paste0("gene",1:15),
+ s1 ="
Error: unexpected ',' in " + s2 = rnorm(15),"
Error: unexpected ',' in " + s3 = rnorm(15),"
问题在于:
1、第三列末尾的“,”多余;
2、由于是复制粘贴的,猜想是多余的“+”
3、刚开始误以为函数rnorm()运用错误。rnorm(15)即rnorm(n=15)
正确代码如下:
df = data.frame(gene = paste0("gene",1:15),
s1 = rnorm(n=15),
s2 = rnorm(n=15),
s3 = rnorm(n=15))