Rev 802 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
791 | werner | 1 | ################################################################ |
2 | ### Create tables in the climate database for iLand using R #### |
||
3 | ################################################################ |
||
4 | |||
5 | # we use the R library RSQLite for all database accesses |
||
6 | # look up the help for the avaiable features. |
||
7 | library(RSQLite) |
||
8 | # |
||
9 | |||
10 | # connect to a existing or create a new database |
||
11 | db.conn <<- dbConnect("SQLite", dbname="e:/Daten/iLand/projects/AFJZ_experiment/database/new_database.sqlite" ) |
||
12 | |||
13 | ## set up a data frame of climate data using right columns and units |
||
14 | # see http://iland.boku.ac.at/climatedata for the required columns |
||
15 | |||
16 | # here load a test data set: |
||
17 | test.data <- read.delim("e:/Daten/BOKU/CCTame/climate/daily/ID014369.csv",sep=";") |
||
18 | head(test.data) |
||
19 | summary(test.data) |
||
20 | |||
21 | # set up the data frame |
||
22 | iland.climate <- data.frame(year=test.data$year, |
||
23 | month=test.data$month, |
||
24 | day=test.data$day, |
||
25 | min_temp=test.data$tmin, |
||
26 | max_temp=test.data$tmax, |
||
27 | prec=test.data$prec, |
||
28 | rad=test.data$rad, |
||
29 | vpd=test.data$vpd) |
||
30 | summary(iland.climate) |
||
31 | |||
32 | |||
33 | ### save into the database: #### |
||
34 | ## the table name is just an example. |
||
35 | ## However, this name is referred to in the project file. |
||
36 | dbWriteTable(db.conn, "climate014369",iland.climate, row.names=F) |
||
37 | |||
38 | # helpful, maybe: |
||
39 | # remove the table again: |
||
40 | dbRemoveTable(db.conn, "climate014369") |
||
41 | |||
42 | ## check if it worked: |
||
43 | cmp <- dbReadTable(db.conn, "climate014369") |
||
44 | summary(cmp) |