我有一个看起来像
的data.frame SNP CHR BP A1 A2 EFF SE P NGT
rs882982 1 100066094 a g -.0179 .006 .002797 28 .486
rs7518025 2 100066515 t c .0198 .0059 .0007438 26 .47
rs6678322 3 100069554 a t .0187 .0059 .001498 25 .452
rs61784986 14 100074953 t c -.0182 .0058 .001748 26 .469
rs7554246 21 100075695 t c -.0167 .006 .004932 26 .455
rs12121193 16 100075777 a t -.0183 .0058 .001652 26 .471
rs835016 3 100078102 t c .02 .0065 .001979 28 .196
我想添加字母" chr"在CHR列中的数字之前。我想要的输出是:
SNP CHR BP A1 A2 EFF SE P NGT
rs882982 chr1 100066094 a g -.0179 .006 .002797 28 .486
rs7518025 chr2 100066515 t c .0198 .0059 .0007438 26 .47
rs6678322 chr3 100069554 a t .0187 .0059 .001498 25 .452
rs61784986 chr14 100074953 t c -.0182 .0058 .001748 26 .469
rs7554246 chr21 100075695 t c -.0167 .006 .004932 26 .455
rs12121193 chr16 100075777 a t -.0183 .0058 .001652 26 .471
rs835016 chr3 100078102 t c .02 .0065 .001979 28 .196
我应该以某种方式使用grep,还是有什么有用的R命令?
答案 0 :(得分:3)
只需使用paste():
df$CHR <- as.character(df$CHR) # in case it is a factor column
df$CHR <- paste("chr", df$CHR, sep="")