![]() To deal with this I wrote a short script to read each csv file and write it to the SQLite database. This format makes most sense for database querying and managing data, and it’s relatively simple to transform data to a format I need. To make matters more complicated the station columns don’t always appear in the same order and the same stations don’t occur each year.Īfter a discussion with the excellent Magi Hagdorn I settled on a table format with columns of Date, Station and Snowline. Super basic, but what about writing to the database, as promised with the blog title?! For my work I have 60+ csv files of Snow Survey data with columns belonging to different stations and rows for different days. You can then do basic tasks like checking what tables are available, or what columns are in a table: in column or table names – this will confuse SQLite. There is included provision to set a primary key and also specify data types (see the SQLite help). If you haven’t already created your database, the dbConnect line above will create it for you and you can set up a table using the below. From the proviso that you’ve already created your database file, connect to it from R by:ĭb = dbConnect(SQLite(), dbname="~/directory/your-db.sqlite") set up the most basic tables, but you can equally do this through RSQLite. I created the shell of my database using SQLite-manager, i.e. To access SQLite through R you’ll need the RSQLite package, add this to the start of your script (first line you only need to do once): The best place to get this is through Firefox add-ons. There’s also an excellent plugin, SQLite-manager, for Firefox that lets you access SQLite. This will almost certainly already be installed on your computer as it’s a backend to web browsers and other software. Once you’ve got R installed (it’s free and runs on pretty much all operating systems) you should make sure you can access SQLite appropriately. In reality as SQLite uses SQL you could also used any other SQL based database and it wouldn’t take much work to use something like Python instead of R to write data. For this I’ll use R for the leg work and SQLite as the database. Since then I’ve not been idle, just busy not writing for my blog! This article is a follow up and describes how to add data to a database. ![]() Some time ago I wrote a post on preparing data for a database.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |