/ 猿问

# 条件的长度> 1，并且仅使用第一个元素

2019-11-19 09:56:30

Ref.y Variant.y

1 T     C

2 G     C

3 A     C

4 T     C

5 C     A

6 G     A

for (i in 1:nrow(trip)) {

if(trip\$Ref.y=='G' & trip\$Variant.y=='T'|trip\$Ref.y=='C' & trip\$Variant.y=='A') {

trip[i, 'mutType'] <- "G:C to T:A"

}

else if(trip\$Ref.y=='G' & trip\$Variant.y=='C'|trip\$Ref.y=='C' & trip\$Variant.y=='G') {

trip[i, 'mutType'] <- "G:C to C:G"

}

else if(trip\$Ref.y=='G' & trip\$Variant.y=='A'|trip\$Ref.y=='C' & trip\$Variant.y=='T') {

trip[i, 'mutType'] <- "G:C to A:T"

}

else if(trip\$Ref.y=='A' & trip\$Variant.y=='T'|trip\$Ref.y=='T' & trip\$Variant.y=='A') {

trip[i, 'mutType'] <- "A:T to T:A"

}

else if(trip\$Ref.y=='A' & trip\$Variant.y=='G'|trip\$Ref.y=='T' & trip\$Variant.y=='C') {

trip[i, 'mutType'] <- "A:T to G:C"

}

else if(trip\$Ref.y=='A' & trip\$Variant.y=='C'|trip\$Ref.y=='T' & trip\$Variant.y=='G') {

trip[i, 'mutType'] <- "A:T to C:G"

}

}

Warning messages:

1: In if (trip\$Ref.y == "G" & trip\$Variant.y == "T" | trip\$Ref.y ==  ... :

the condition has length > 1 and only the first element will be used

mutType

A:T to G:C

G:C to C:G

A:T to C:G

A:T to G:C

G:C to T:A

G:C to A:T

## 2 回答

POPMUISE

c(TRUE, TRUE) & c(TRUE, FALSE)

# [1] TRUE FALSE

# c(TRUE, TRUE) && c(TRUE, FALSE)

[1] TRUE

mut1 <- trip\$Ref.y=='G' & trip\$Variant.y=='T'|trip\$Ref.y=='C' & trip\$Variant.y=='A'

trip[mut1, "mutType"] <- "G:C to T:A"

for (i in 1:nrow(trip)) {

if(trip\$Ref.y[i]=='G' & trip\$Variant.y[i]=='T'|trip\$Ref.y[i]=='C' & trip\$Variant.y[i]=='A') {

trip[i, 'mutType'] <- "G:C to T:A"

}

else if(trip\$Ref.y[i]=='G' & trip\$Variant.y[i]=='C'|trip\$Ref.y[i]=='C' & trip\$Variant.y[i]=='G') {

trip[i, 'mutType'] <- "G:C to C:G"

}

else if(trip\$Ref.y[i]=='G' & trip\$Variant.y[i]=='A'|trip\$Ref.y[i]=='C' & trip\$Variant.y[i]=='T') {

trip[i, 'mutType'] <- "G:C to A:T"

}

else if(trip\$Ref.y[i]=='A' & trip\$Variant.y[i]=='T'|trip\$Ref.y[i]=='T' & trip\$Variant.y[i]=='A') {

trip[i, 'mutType'] <- "A:T to T:A"

}

else if(trip\$Ref.y[i]=='A' & trip\$Variant.y[i]=='G'|trip\$Ref.y[i]=='T' & trip\$Variant.y[i]=='C') {

trip[i, 'mutType'] <- "A:T to G:C"

}

else if(trip\$Ref.y[i]=='A' & trip\$Variant.y[i]=='C'|trip\$Ref.y[i]=='T' & trip\$Variant.y[i]=='G') {

trip[i, 'mutType'] <- "A:T to C:G"

}

}

• 2 回答
• 0 关注
• 206 浏览

0/150