假设我有包含此信息的 txt 文件
exons affected_exon
24 22
37 7
14 7
33 3
So what I want to do is to create a new col called splicing like this:
exons affected_exon splicing
24 22 midle
37 7 middle
14 14 last
33 1 first
所以对于拼接,我希望以下内容:
if affected_exon = 1 -> complete with first
if affected exon = exons -> complete with last
if affected exon < exons (and > 1) -> complete with middle
目前我在 R 中有这段代码,但不起作用,我不知道为什么:
out <- read.delim("out.txt", sep = "t", header = T)
scans <- out$exons
exon <- out$affected_exon
cluster <- out$group
for (i in out ){
if (scans == exon){
cluster <- c("last")
}
if (exon == 1){
cluster <- c("first")
}
if (exon < scans & exon > 1){
cluster <- c("middle")
}
}
我命令将其读取为data.table
:
data_set = data.table::fread("out.txt", header = TRUE)
然后,您可以为所有人设置:
data_set[, cluster := "middle"]
并将其更改为最后一个和第一个:
data_set[affected_exon == 1, cluster := "first"]
data_set[affected_exon == exons, cluster := "last"]
你可以这样写:
data.table::fwrite(data_set, "textfile.txt", sep = "t")
希望对你有帮助