You need to sign in or sign up before continuing.
Newer
Older
---
output:
html_document: default
pdf_document: default
---
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Some useful functions for working with (German) farm structure survey (FSS) data.
# Installation
You can install the GitLab version of FSS from [GitLab](https://git-dmz.thuenen.de/mindstep/fss) with:
```{r}
devtools::install_git("https://git-dmz.thuenen.de/mindstep/fss")
```
Then the Related R packages can be installed.
```{r}
library(FSS)
```
# Example
A little example for one specific function from the FSS package.
## Test a function
Here we will test one of the provided functions: `generateFakeFSSData_DE()`. We generate some basic variables, which are automatically produced. We set an additional variable to
be generated, namely C0300. The variable will be a continuous variable.
```{r}
FSS_data_DE <- generateFakeFSSData_DE(C0codes = "C0300")
```
### Add a specific categorical variable
No we will add a specific variable, i.e. a categorical variable if a farm is an organic farm. This will be randomly distributed. The probability of a farm to be organic is 20%.
```{r,message=FALSE}
library(tidyverse)
FSS_data_DE <- FSS_data_DE %>%
mutate(C0501=sample(c(0,1),
size = nrow(FSS_data_DE),
replace = TRUE,
prob = c(0.8,0.2)))
```
### Some analysis
After that we analyse the data regarding the number of farms that are organic (C0501) for each year (C0008U1) and farm type (C0060UG1).
```{r}
FSS_data_DE %>% group_by(C0008U1,C0060UG1,C0501) %>%
count() %>%
pivot_wider(names_from = C0060UG1, values_from = n) %>%
knitr::kable()
```
| C0008U1| C0501| 1| 2_3| 45| 46_48| 5| 6_7_8|
|-------:|-----:|-----:|-----:|-----:|-----:|-----:|-----:|
| 1999| 0| 57491| 16693| 29578| 44526| 33620| 55483|
| 1999| 1| 14461| 4222| 7491| 10998| 8288| 13827|
| 2003| 0| 55229| 16216| 28762| 43023| 32228| 53946|
| 2003| 1| 13748| 4142| 7093| 10744| 8018| 13554|
| 2007| 0| 53467| 15357| 27391| 41918| 31202| 51658|
| 2007| 1| 13150| 3874| 6794| 10456| 7782| 12846|
| 2010| 0| 51228| 15182| 26514| 40054| 29784| 49768|
| 2010| 1| 12838| 3730| 6667| 9999| 7495| 12446|
| 2013| 0| 14310| 4257| 7405| 11242| 8477| 13920|
| 2013| 1| 3764| 1051| 1810| 2775| 2143| 3508|
| 2016| 0| 49581| 14520| 25711| 38544| 28840| 48287|
| 2016| 1| 12510| 3642| 6350| 9564| 7200| 12102|
| 2020| 0| 47565| 13932| 24603| 36770| 28096| 46413|
| 2020| 1| 11938| 3420| 6248| 9284| 7030| 11512|