0

Background: I work with animals, and I have a way of scoring each pet based on a bunch of variables. This score indicates to me the health of the animal, say a dog.

Best practise: Let's say I wanted to create a bunch of lookup tables to recreate this scoring model of mine, that I have only stored in my head. Nowhere else. My goal is to import my scoring model into R. What is the best practise of doing this? I'm gonna use it to make a function where I just type in the variables and I will get a result back.

I started writing it directly into Excel, with an idea of importing it into R, but I wonder if this is bad practise?

model in excel

I have thought of json-files, which I have no experience with, or just hardcoding a bunch of lists in R...

Helen
  • 533
  • 12
  • 37
  • Possible duplicate of [R - Excel VLOOKUP equivalent - Lookup, replace](https://stackoverflow.com/questions/24012636/r-excel-vlookup-equivalent-lookup-replace) – jogo Jun 03 '19 at 09:48
  • I'm not looking for a function here... – Helen Jun 03 '19 at 09:56
  • Are you asking specifically about whether it's ok to write your lookup table in Excel, or more generally about how you'd make a lookup table that allows ranges? – divibisan Jun 03 '19 at 17:55
  • Both, I guess. What would the best practise be, because I have to write a function in R to look up values in each sheet (if I read this into R I will create a list of data frames). – Helen Jun 03 '19 at 18:12

1 Answers1

1

Writing the tables to an excel file (or multiple excel files) and reading them with R is not bad practice. I guess it comes down to the number of excel files you have and your preferences.

R can connect to pretty much any of the most common file types (csv, txt, xlsx, etc.) and you will be fine reading them in R. Another type is the .RData files which are native in R. You can use them with save, load:

df2 <- mtcars
save(df2, file = 'your_path_here')

load(file = 'your_path_here')

Any of the above is fine as long as your data is not too big (e.g. if you start having 100 excel files which you need to update frequently, your data is probably becoming too big to maintain in excel). If that ever happens, then you should consider creating a data base (e.g. MySQL, SQLite, etc.) and storing your data there. R would then connect to the data base to access the data.

LyzandeR
  • 37,047
  • 12
  • 77
  • 87