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