I have continuous sapflow data (averaged for every 10 minutes) in degree celsius recorded by heat-dissipation sensors for 30 trees (30 sapflow average value columns). But for proper analysis and calculation of sapflow data, TREX package is required. Since I haven't used it before, I had some error due to improper data structure. My data couldn't pass the "is.trex()" function. I have uploaded a small section of my dataset.
#data format
> timestamp SF_Avg.1. SF_Avg.2. SF_Avg.3. SF_Avg.4.
1 TS DegC DegC DegC DegC
2 Avg Avg Avg Avg
3 2024-12-25 17:10:00 4.096447 9.202514 7.594289 5.357638
4 2024-12-25 17:20:00 4.093174 9.271017 7.700016 5.424657
5 2024-12-25 17:30:00 4.328177 9.294633 7.721289 5.534774
6 2024-12-25 17:40:00 4.510964 9.441677 7.854154 5.740962
#usage of code
>?is.trex
>>""is.trex(data, tz = 'UTC', tz.force = FALSE, time.format = '%m/%d/%y %H:%M:%S',
solar.time = TRUE, long.deg = 7.7459, ref.add = FALSE, df = FALSE)""
How can I structure my data to pass this code?
The is.trex function allows two formats for the "data" argument. Both must be data frames:
Two columns where the first column is character and called "timestamp" and the second column is numeric and called "value"; or
Four columns containing the year of measurements (integer), day of year (integer), hour (character), and the measurement "value" (integer).
The help page states this very clearly. Your data does not meet either of these two formats for a few reasons. Firstly, there is no column called "value". Secondly, the columns are not in the required classes.
To fix the first problem, I would edit the source data by manually removing the second and third rows (or you can do that in R, but it's better to get the data types correct from the start). Assuming you've done this, you can then import the data, followed by a quick check:
sapflow <- read.table("sapflow.txt", header=TRUE)
head(sapflow)
timestamp SF_Avg.1. SF_Avg.2. SF_Avg.3. SF_Avg.4.
1 2024-12-25 17:10:00 4.096447 9.202514 7.594289 5.357638
2 2024-12-25 17:20:00 4.093174 9.271017 7.700016 5.424657
3 2024-12-25 17:30:00 4.328177 9.294633 7.721289 5.534774
4 2024-12-25 17:40:00 4.510964 9.441677 7.854154 5.740962
The timestamp looks ok, but there is no "value" column. You can use the transform
function to create a new column called "value" from each of the other columns one by one and then run the is.trex
command separately.
SF1 <- transform(sapflow, value=SF_Avg.1.)
SF2 <- transform(sapflow, value=SF_Avg.2.) # etc.
is.trex(SF1, tz = 'UTC', ...) # etc.
2024-03-25 17:40:00 2024-03-25 17:50:00 2024-03-25 18:00:00 2024-03-25 18:10:00
4.096447 4.093174 4.328177 4.510964