0

I am following the instructions for population genetics in R, and I was able to succesfully follow the instructions, but I am having trouble replicating the functions with my own data. I have been able to import my data (Coysats) in many different formats, so getting data into R Studio is not the problem. I begin having a problem when I try to load the data using the function:

    data("Coysats")

but I am met with the following message:

    Warning message:In data("Coysats") : data set ‘Coysats’ not found

I am able to get results with the function:

    summary(Coysats)

I think this is because the original dataset used in the example that I'm looking comes from a package, so I attempted creating a package, but quickly became even more confused. I simply want to be able to load my data into the console in order to properly use the functions that follow in the example. I am still quite new to R and programming in general, so I would greatly appreciate answers being as specific as possible when describing how to load separate data that is not in a package, and is already in the global environment. Thank you

MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • You only use `data()` when loading data from packages (and even that's not always required any more if they are lazy loaded). If `summary(Coysats)` works, then there's no need to try to get the `data()` part to work. Is there something else that doesn't work that you think calling `data()` will fix? – MrFlick Jul 14 '18 at 00:51
  • If data is already in the global environment, then you can just refer to it by its name. Everywhere they used `nancycats` you can just use `Coystats`, provided the two are the same format and everything. There is nothing to "load". If you are "having trouble replicating the functions", it is probably not because that data wasn't loaded. I suggest you try to resubmit if you can figure out a more specific problem you're having. – Calum You Jul 14 '18 at 01:13
  • @MrFlick I see what you're saying with the `summary()`, so I tried to continue without using `data()` and the error code stopped appearing. There is a later problem with the next part `plot(div$Hobs, xlab="Loci number", ylab="Observed Heterozygosity", main="Observed heterozygosity per locus")` that appears with the error code `Error in div$Hobs : $ operator is invalid for atomic vectors` I think this means that there is something wrong with my data formatting, but I formatted as closely as I could to `nancycats`. – Melanie Croft Jul 16 '18 at 17:54
  • If you have a different problem, you should probably start a new question. Be sure to include the exact error message you are getting or even better a reproducible example. – MrFlick Jul 16 '18 at 17:56
  • It sounds like div isn’t a data frame, but just a vector. How did you create it? What is it’s `class()`? – MrFlick Jul 16 '18 at 17:57
  • @MrFlick I didn't create div$Hobs, and the class comes back with `Error in div$Hobs : $ operator is invalid for atomic vectors` is this what you were asking? I think I'm going to start a new question. How might I make my example "reproducible?" – Melanie Croft Jul 16 '18 at 18:37
  • Well, you were calling `plot(div$Hobs, ...`) so I assumed you had created that variable. Where did `div` come from? It would be `class(div)` (don't include the column name). Here are some [tips on making a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Jul 16 '18 at 18:46
  • @MrFlick `class(div)` is `table` I'll check the link out, thank you very much for responding! – Melanie Croft Jul 16 '18 at 18:55

0 Answers0