0

I have a dataframe consisting of pedigree data, with columns ID, DADID, MOMID, SEX and a few others for use in r packages kinship2 and optiSel. Currently my data is in factor form (the IDs are described by the individual's names rather than numbers) and this causes a problem when trying to format the resulting pedigrees from optiSel.

I'm not sure how familiar any of you are with optiSel, but it has a subPed function that creates a small pedigree from the large dataset given and uses values from the Kinship2 package to adjust the aesthetics of the plotted pedigree.

My issue arose when I tried to plot a larger pedigree, because the names overlapped eachother significantly and made it impossible to read. I couldn't adjust the width or length of the text nor the plot itself because of incompatibility of the kinship2 dataframe requirements vs optiSel. Kinship2 I believe requires the IDs to be in numeric form, so my goal is to find a quick function to change my characters to numbers that are consistent amidst all relationships in my pedigree data.
More specifically, I have one individual in a row under column ID that appears in another row under column DADID, and when I change their name to a number, I need these numbers to be equal (consistent with that character identity).

I cannot seem to find a quick way of doing this, as there are over 700 individuals in my pedigree data thus far.

sped<-subPed(pedigree, keep = c("Customs Ajax AAD"), prevGen = 2, succGen = 2)
pedplot(sped, cex = 0.2)

#The resulting pedigree from this is extremely small, but I can't make it any larger to see the names because there isn't sufficient room

pedplot(sped, cex = 0.2, width = 8)

#nothing changes because the 'width' aest isn't compatible

#attempt to plot with kinship2 instead:
plot.pedigree(sped, id=sped$Indiv)
Error in plot.pedigree(sped, id = sped$Indiv) : Wrong length for id


#trying to change characters to numbers:

pednum<-as.numeric(pedigree$ID)

#this only changes those of one column, and doesn't integrate it

#rename and replace functions don't work
Theo
  • 57,719
  • 8
  • 24
  • 41
vschill
  • 1
  • 2
  • 1
    Could you edit your post to make it as concise as possible? Also add sample data to work with. – NelsonGon Jun 28 '19 at 12:58
  • Possible duplicate of [How to create a consecutive index based on a grouping variable in a dataframe](https://stackoverflow.com/questions/6112803/how-to-create-a-consecutive-index-based-on-a-grouping-variable-in-a-dataframe) – IceCreamToucan Jun 28 '19 at 13:13
  • If you want a numeric ID for each value of a variable `x`, you can use the method in the above link of `match(x, unique(x))`. Then if you want another column `y` with the same values to have the same value->number mapping you can use `match(y, unique(x))`. If `y` has some values not in `x` you would need to replace `unique(x)` in both `match` calls with `unique(c(x, y))`. – IceCreamToucan Jun 28 '19 at 13:50

0 Answers0