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