Hi dartR community,
This is a rookie question that I thought I could easily solve, but haven’t been able to. I hope somebody has a quick fix.
I am working with a genlight file, and for historical reasons my pop slot is filled with labels for high-level geographic regions, whereas what I would like to have in that slot is finer scale sampling sites. Typically there may be several sites within the regions.
The gl.recode.pop function doesn’t seem appropriate because it designed for one for one population name changes, or combining pops.
If I import a text file vector of pop names (i.e. the vector is as long as the number of individuals) and try to place it in the pop slot by e.g.
Site_names <- read.table(file = "Site_names.txt", header = FALSE)
my.gl$pop <- Site_names
I get an error like:
Error in checkSlotAssignment(object, name, value) :
assignment of an object of class “data.frame” is not valid for slot ‘pop’ in an object of class “genlight”; is(value, "factorOrNULL") is not TRUE
I don’t have that problem if I import data into $other slots.
No doubt a basic error, but I am hoping an R guru can set me straight.
Cheers,
Olly
--
You received this message because you are subscribed to the Google Groups "dartR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dartr+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/ME2PR01MB238824B855E5091C882C3091FF4F0%40ME2PR01MB2388.ausprd01.prod.outlook.com.
Thanks Arthur,
In this case I am already past the QC stage etc and don’t have the sites included in my individual metrics (in hindsight an error!).
Cheers,
Olly
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/CAH6j3HV55N5xbMMsg9LTZ-MzCs-HHt5y-p1tdp7ttAAfQZrMqQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/ME2PR01MB23882427E0459AC749272D7BFF4F0%40ME2PR01MB2388.ausprd01.prod.outlook.com.
Thanks Arthur.
With some minor tweaking it worked!
Cheers,
Olly
--
For the record….
#Switching the "pop" name to Region - which is more appropriate
test.gl$other$Region <-test.gl$pop
#Now bring in the actual site names to the pop slot#
Site_names <- read.csv(file = "Site_names.csv", header = TRUE) #import the vector
test.gl@other$ind.metrics <- Site_names #The variable is labelled Site in the input file (header), this will be the label for the vector within ind.metrics
test.gl <- gl.reassign.pop(test.gl,as.pop="Site") #The function looks in ind.metrics for a vector called Site
test.gl #have a look
levels(test.gl$pop)
levels(test.gl$other$Region)
To view this discussion on the web visit https://groups.google.com/d/msgid/dartr/CAH6j3HXZ7AySBMqnrRwiPzebKyCo4cv31SV8pghogryRoVruQg%40mail.gmail.com.