# Create a simple exdf object with two columns (`A` and `B`) and default values
# for its units and categories.
simple_exdf <- exdf(data.frame(A = c(3, 2, 7, 9), B = c(4, 5, 1, 8)))
print(simple_exdf)
# Add a new column called 'C' with units 'u1' and category 'cat1' whose value is
# 1000.
simple_exdf <- set_variable(simple_exdf, 'C', 'u1', 'cat1', 1000)
# Set the value of the 'B' column to 2000 when 'A' is 3, to 3000 when 'A' is 9,
# and to 4000 for all other values of 'A'. Do not modify its units or category.
simple_exdf <- set_variable(
simple_exdf,
'B',
value = 4000,
id_column = 'A',
value_table = list('3' = 2000, '9' = 3000)
)
print(simple_exdf)
# Take the same operations, but using a data frame instead
simple_df <- data.frame(A = c(3, 2, 7, 9), B = c(4, 5, 1, 8))
simple_df <- set_variable(simple_exdf$main_data, 'C', 'u1', 'cat1', 1000)
simple_df <- set_variable(
simple_df,
'B',
value = 4000,
id_column = 'A',
value_table = list('3' = 2000, '9' = 3000)
)
print(simple_df)
# As a more realistic example, load a Licor file and set different values of
# mesophyll conductance for each species in the data set.
licor_file <- read_gasex_file(
PhotoGEA_example_file_path('ball_berry_1.xlsx')
)
licor_file <- set_variable(
licor_file,
'gmc',
'mol m^(-2) s^(-1) bar^(-1)',
'',
id_column = 'species',
value_table = list(soybean = 0.9, tobacco = 1.1)
)
print(licor_file[, c('species', 'gmc'), TRUE])
Run the code above in your browser using DataLab