Я пытаюсь запустить этот скрипт:
input <- read.csv ("trio.csv")
for (i in 1:nrow(input)) {
if (input[i, 6] == input[i, 2]) {
if (input[i, 7] == input[i, 4] |
input[i, 7] == input[i, 7]) {
print ("h1")
} else {
print ("not h1")
}
} else if (input[i, 6] == input[i, 3]) {
if (input[i, 7] == input[i, 4] | input[i, 7] == input[i, 7]) {
print ("h1")
} else {
print ("not h1")
}
} else {
print("not h1")
}
}
for (j in 1:nrow(input)) {
if (input[j, 7] == input[j, 2]) {
if (input[j, 6] == input[j, 4] | input[j, 6] == input[j, 7]) {
print ("h2")
} else {
print ("not h2")
}
} else if (input[j, 7] == input[j, 3]) {
if (input[j, 6] == input[j, 4] |input[j, 6] == input[j, 7]) {
print ("h2")
} else {
print ("not h2")
}
} else {
print("not h2")
}
}
Файл trio.csv состоит из 7 столбцов и 100 строк, вот пример того, как выглядит trio.csv:
dput(head(input))
structure(list(familyID = c(1001L, 1004L), Pat1 = structure(2:1, .Label =
c("REF", "X1"), class = "factor"), Pat2 = structure(1:2, .Label = c("C2",
"REF"), class = "factor"), Mat1 = structure(1:2, .Label = c("C2",
"REF"), class = "factor"), Mat2 = structure(c(1L, 1L), .Label = "C2",
class = "factor"),
Ch1 = structure(2:1, .Label = c("REF", "X1"), class = "factor"),
Ch2 = structure(1:2, .Label = c("C2", "REF"), class = "factor")),
row.names = 1:2, class = "data.frame")
Как сохранить результаты первого и второго циклов в двух разных столбцах в новом файле?