Untitled

mail@pastecode.io avatar
unknown
r
2 years ago
1.2 kB
3
Indexable
Never
library(pedigreemm)
library(MASS)


SUBSET_LENGTH <- 1000

data = read.table("http://theta.edu.pl/wp-content/uploads/2021/03/dane.csv", header = TRUE, sep = ";")
data = data[0:SUBSET_LENGTH, ]

ID = c(as.character(data$ID), as.character(data$DamID), as.character(data$SireID))
ID = unique(ID)
ID = ID[ID != "0"]
newData =data.frame(ID)
head(newData)

newData = merge(newData, data, by = "ID", all.x = TRUE)
newData = newData[, c(-4, -6)]
newData = newData[order(newData$Byear),]

n = nrow(newData)

newData$newID = 1:n

data_tmp = newData[, c(1, 5)]
colnames(data_tmp) = c("SireID", "newSireID")

newData = merge(newData, data_tmp, by = "SireID", all.x = TRUE)

data_tmp = newData[, c(2, 5)]
colnames(data_tmp) = c("DamID", "newDamID")

newData = merge(newData, data_tmp, by = "DamID", all.x = TRUE)
newData = newData[order(newData$Byear),]

newData = newData[, c(-1, -2, -4)]

newData$newSireID[newData$newSireID > newData$newID & !is.na(newData$newSireID)] = NA
newData$newDamID[newData$newDamID > newData$newID & !is.na(newData$newDamID)] = NA

newData <- newData[order(newData$newID), ]
ped <- pedigree(sire=newData$newSireID, dam=newData$newDamID, label=newData$newID)



# Odtąd kod można wrzucić do sprawka
A <- as.matrix(getA(ped))