Data format and running Mann Kendall

I have made a csv file below for chemical readings

Headers are:
Site, date (##/##/###), Value

Information is:
Site is the same (for now, eg F1), Date is one sample per month, value is anything from 0 to 30

For now im only looking at one years worth of data. I need a guide to get the data in the correct table format and codes needed to get the data into R studio.

The next problem im having is running Mann Kendal test of the data and viewing the results. Iv been trying for a couple of days now with no joy.

Any help would be great

R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Hi @Orionm45,
Welcome to the RStudio Community Forum.
Here is a minimal reproducible example (MRE) to get you started. Just cut-and-paste this code into a new R script file which you open in RStudio, and then run it. Of course, your data will be coming from your .CSV file (see help(read.csv) for examples):

a <- "
site, my_date, value
F1, 01/01/2019, 13
F1, 01/02/2019, 16
F1, 01/03/2019, 14
F1, 01/04/2019, 18
F1, 01/05/2019, 23
F1, 01/06/2019, 21
F1, 01/07/2019, 22
F1, 01/08/2019, 25
F1, 01/09/2019, 26
F1, 01/10/2019, 26
F1, 01/11/2019, 29
F1, 01/12/2019, 30

in.df <- read.csv(text=a, header=TRUE, stringsAsFactors=FALSE)
in.df$my_date <- as.Date(in.df$my_date, format="%d/%m/%Y")
plot(value ~ my_date, type="b", data=in.df)
lines(lowess(in.df$my_date, in.df$value))


In future, if you provide a MRE you are much more likely to get help from forums such as this.

p.s. Try to avoid using the '#' symbol in data files - it signifies a 'comment' in R and will cause you problems.

Hi @DavoWW

Thank you so much for the reply. I am relatively new to R so still finding my feet.

From using your reply i was able to obtain a result.

Just as a learning curve would you be able to explain a few things. When i paste your code into R i receive the following errors. ""Test is the name of my file""

Test(<- read.csv(text=a, header=TRUE, stringsAsFactors=FALSE)
Error in textConnection(text, encoding = "UTF-8") : object 'a' not found

Test$my_date <- as.Date(Test$my_date, format="%d/%m/%Y")
Is this code simply to ensure all dates in formatted to the above?

My next question is im also trying to perform this on a full data set with different sites and years. Is there a way to tell R to give me the results for Mann Kendall test for each site for all years or each sites per year?

Thank you in advance


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.