1

我有一个这样的数据框

TargetID       A    B  knowngene
cg00000108 0.8644845 0.9289447 uc003chb.3
cg00000108 0.8644845 0.9289447 uc003cha.4
cg00000109 0.8810606 0.9109397 uc003fhy.3
cg00000109 0.8810606 0.9109397 uc003fhz.4
cg00000109 0.8810606 0.9109397 uc003fia.3

我们的想法是改变它以获得这个新的

knowngene    Meth_info
uc003chb.3   cg00000108;0.8644845;0.9289447
uc003cha.4   cg00000108;0.8644845 0.9289447
uc003fhy.3   cg00000109;0.8810606;0.9109397
uc003fhz.4   cg00000109;0.8810606;0.9109397
uc003fia.3   cg00000109;0.8810606;0.9109397
4

2 回答 2

2

这几乎是从duplicated.data.frame

dat <- read.table(text = "TargetID       A    B  knowngene
cg00000108 0.8644845 0.9289447 uc003chb.3
cg00000108 0.8644845 0.9289447 uc003cha.4
cg00000109 0.8810606 0.9109397 uc003fhy.3
cg00000109 0.8810606 0.9109397 uc003fhz.4
cg00000109 0.8810606 0.9109397 uc003fia.3", header = TRUE)

# Paste together the first three columns
theStrings <- do.call(paste,c(dat[,-4],sep=";"))

# create a data.frame of the results
(dat2 <- data.frame(dat[,4, drop = FALSE], Meth_info = theStrings))

#    knowngene                     theStrings
# 1 uc003chb.3 cg00000108;0.8644845;0.9289447
# 2 uc003cha.4 cg00000108;0.8644845;0.9289447
# 3 uc003fhy.3 cg00000109;0.8810606;0.9109397
# 4 uc003fhz.4 cg00000109;0.8810606;0.9109397
# 5 uc003fia.3 cg00000109;0.8810606;0.9109397
于 2012-11-16T10:08:07.647 回答
0

试试这个:

df2 <- data.frame(knowngene, 
          Meth_info= paste(TargetID,";",A,";",B,sep="")
          ,stringsAsFactors=F)

在向量上使用粘贴只是逐行粘贴项目 - 非常方便。

于 2012-11-16T10:36:53.490 回答