master
marcgauch 2022-11-18 21:10:07 +01:00
parent afd7d1babf
commit 51cd711da8
2 changed files with 90 additions and 123 deletions

View File

@ -1509,8 +1509,8 @@ if (!require(moments)){
<h2><span class="header-section-number">2.1</span> Frequency Table
ordered from wish.com</h2>
<pre class="r"><code>freq &lt;- function(data) {
na_count = length(data[is.na(data)])
valid_count = length(data)-na_count
na_count &lt;- length(data[is.na(data)])
valid_count &lt;- length(data) - na_count
frequency &lt;- table(data)
p &lt;- prop.table(frequency)
percent &lt;- round(p * 100, digits = 2)
@ -1526,10 +1526,8 @@ ordered from wish.com</h2>
count &lt;- c(valid_count, na_count, valid_count + na_count)
percent &lt;- c(valid_percent, na_percent, valid_percent + na_percent)
totall &lt;- c(valid_count+na_count, valid_percent+na_percent)
df &lt;- data.frame(count, percent, row.names = c(&quot;valid&quot;, &quot;NA&quot;, &quot;Total&quot;))
print(df)
}</code></pre>
<p><em>Source: <a href="https://tellmi.psy.lmu.de/tutorials/deskriptive-statistiken-und-grafiken.html#haeufigkeiten-diskret" class="uri">https://tellmi.psy.lmu.de/tutorials/deskriptive-statistiken-und-grafiken.html#haeufigkeiten-diskret</a>
and adapted</em></p>
@ -1848,7 +1846,6 @@ are NOT numeric.</p>
&quot;A7&quot; = &quot;W007&quot;,
&quot;A8&quot; = &quot;W008&quot;,
&quot;A9&quot; = &quot;W009&quot;,
&quot;B1&quot; = &quot;K001&quot;,
&quot;B2&quot; = &quot;K002&quot;,
&quot;B3&quot; = &quot;K003&quot;,
@ -1858,37 +1855,30 @@ are NOT numeric.</p>
&quot;B7&quot; = &quot;K007&quot;,
&quot;B8&quot; = &quot;K008&quot;,
&quot;B9&quot; = &quot;K009&quot;,
&quot;C1_1&quot; = &quot;TK001_01&quot;,
&quot;C1_2&quot; = &quot;TK001_02&quot;,
&quot;C1_3&quot; = &quot;TK001_03&quot;,
&quot;C1_4&quot; = &quot;TK001_04&quot;,
&quot;C2_1&quot; = &quot;TK002_01&quot;,
&quot;C2_2&quot; = &quot;TK002_02&quot;,
&quot;C2_3&quot; = &quot;TK002_03&quot;,
&quot;C2_4&quot; = &quot;TK002_04&quot;,
&quot;C3_1&quot; = &quot;TK003_01&quot;,
&quot;C3_2&quot; = &quot;TK003_02&quot;,
&quot;C3_3&quot; = &quot;TK003_03&quot;,
&quot;C3_4&quot; = &quot;TK003_04&quot;,
&quot;C4_1&quot; = &quot;TK004_01&quot;,
&quot;C4_2&quot; = &quot;TK004_02&quot;,
&quot;C4_3&quot; = &quot;TK004_03&quot;,
&quot;C4_4&quot; = &quot;TK004_04&quot;,
&quot;C5_1&quot; = &quot;TK005_01&quot;,
&quot;C5_2&quot; = &quot;TK005_02&quot;,
&quot;C5_3&quot; = &quot;TK005_03&quot;,
&quot;C5_4&quot; = &quot;TK005_04&quot;,
&quot;C6_1&quot; = &quot;TK006_01&quot;,
&quot;C6_2&quot; = &quot;TK006_02&quot;,
&quot;C6_3&quot; = &quot;TK006_03&quot;,
&quot;C6_4&quot; = &quot;TK006_04&quot;,
&quot;D1_1&quot; = &quot;H001_001&quot;,
&quot;D1_2&quot; = &quot;H001_002&quot;,
&quot;D1_3&quot; = &quot;H001_003&quot;,
@ -1896,23 +1886,15 @@ are NOT numeric.</p>
&quot;D1_5&quot; = &quot;H001_005&quot;,
&quot;D1_6&quot; = &quot;H001_006&quot;,
&quot;D1_7&quot; = &quot;H001_007&quot;,
&quot;D2&quot; = &quot;H002&quot;,
&quot;D3&quot; = &quot;H003&quot;,
&quot;D4&quot; = &quot;H004&quot;,
&quot;D4_comment&quot; = &quot;H004_other&quot;,
&quot;D5&quot; = &quot;H005&quot;,
&quot;D5_comment&quot; = &quot;H005_other&quot;,
&quot;D6&quot; = &quot;H006&quot;,
&quot;D7&quot; = &quot;H007&quot;,
&quot;D8&quot; = &quot;H008&quot;,
&quot;E1&quot; = &quot;R1&quot;
)</code></pre>
<p>Then we change the datatype and fix the values</p>
@ -2280,8 +2262,10 @@ Data</h2>
count(value) %&gt;%
mutate(percentage = prop.table(n) * 100)
print(tmp, n = 100)
ggplot(tmp,
aes(x = value, y=n)) +
ggplot(
tmp,
aes(x = value, y = n)
) +
geom_bar(stat = &quot;identity&quot;) +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
}</code></pre>

View File

@ -35,8 +35,8 @@ if (!require(moments)){
## Frequency Table ordered from wish.com
```{r}
freq <- function(data) {
na_count = length(data[is.na(data)])
valid_count = length(data)-na_count
na_count <- length(data[is.na(data)])
valid_count <- length(data) - na_count
frequency <- table(data)
p <- prop.table(frequency)
percent <- round(p * 100, digits = 2)
@ -52,10 +52,8 @@ freq <- function(data){
count <- c(valid_count, na_count, valid_count + na_count)
percent <- c(valid_percent, na_percent, valid_percent + na_percent)
totall <- c(valid_count+na_count, valid_percent+na_percent)
df <- data.frame(count, percent, row.names = c("valid", "NA", "Total"))
print(df)
}
```
*Source: https://tellmi.psy.lmu.de/tutorials/deskriptive-statistiken-und-grafiken.html#haeufigkeiten-diskret and adapted*
@ -131,7 +129,6 @@ litdata <- litdata %>% rename(
"A7" = "W007",
"A8" = "W008",
"A9" = "W009",
"B1" = "K001",
"B2" = "K002",
"B3" = "K003",
@ -141,37 +138,30 @@ litdata <- litdata %>% rename(
"B7" = "K007",
"B8" = "K008",
"B9" = "K009",
"C1_1" = "TK001_01",
"C1_2" = "TK001_02",
"C1_3" = "TK001_03",
"C1_4" = "TK001_04",
"C2_1" = "TK002_01",
"C2_2" = "TK002_02",
"C2_3" = "TK002_03",
"C2_4" = "TK002_04",
"C3_1" = "TK003_01",
"C3_2" = "TK003_02",
"C3_3" = "TK003_03",
"C3_4" = "TK003_04",
"C4_1" = "TK004_01",
"C4_2" = "TK004_02",
"C4_3" = "TK004_03",
"C4_4" = "TK004_04",
"C5_1" = "TK005_01",
"C5_2" = "TK005_02",
"C5_3" = "TK005_03",
"C5_4" = "TK005_04",
"C6_1" = "TK006_01",
"C6_2" = "TK006_02",
"C6_3" = "TK006_03",
"C6_4" = "TK006_04",
"D1_1" = "H001_001",
"D1_2" = "H001_002",
"D1_3" = "H001_003",
@ -179,23 +169,15 @@ litdata <- litdata %>% rename(
"D1_5" = "H001_005",
"D1_6" = "H001_006",
"D1_7" = "H001_007",
"D2" = "H002",
"D3" = "H003",
"D4" = "H004",
"D4_comment" = "H004_other",
"D5" = "H005",
"D5_comment" = "H005_other",
"D6" = "H006",
"D7" = "H007",
"D8" = "H008",
"E1" = "R1"
)
```
@ -289,7 +271,6 @@ litdata$D7 <- as.numeric(litdata$D7)
litdata$D8 <- as.factor(litdata$D8)
# skipping E1 because it's a free text
```
@ -323,8 +304,10 @@ displayFunction1 <- function(table, column) {
count(value) %>%
mutate(percentage = prop.table(n) * 100)
print(tmp, n = 100)
ggplot(tmp,
aes(x = value, y=n)) +
ggplot(
tmp,
aes(x = value, y = n)
) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
}