Oliver Nakoinz, Lizzie Scholtus, Néhémie Strupler
sum()
function andarchdata
by
apply()
,sum()
function and## [1] 2745
## [1] 1.333333
This version is required for apply.
## [1] 1.333333
archdata
by
apply()
,The package archdata
(Carlson/Roth
2021) provides some archaeological data.
Grave | Mno | FL | BH | BFA | FA | CD | BRA | ED | FEL | C | BW | BT | FEW | Coils | Length |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
149 | 389 | 93 | 24 | 7 | 10 | 16 | 1 | 13 | 31 | 47 | 3.5 | 3.5 | NA | 4 | 114 |
190 | 615 | 21 | 7 | 6 | 9 | 6 | 5 | 2 | 11 | 10 | 3.5 | 1.7 | NA | 12 | 35 |
161 | 125 | 33 | 15 | 2 | 8 | 7 | 3 | 8 | 10 | 20 | 3.9 | 3.2 | NA | 4 | 60 |
31 | 812 | 23 | 26 | 4 | 7 | 9 | 5 | 12 | 1 | 16 | 6.2 | 7.7 | 2.8 | 4 | 74 |
49 | 798 | 20 | 23 | 2 | 8 | 7 | 1 | 8 | 5 | 16 | 7.7 | 5.2 | 2.6 | 6 | 68 |
6 | 673 | 27 | 15 | 6 | 8 | 7 | 5 | 3 | 11 | 11 | 3.7 | 3.5 | 1.8 | 4 | 55 |
length | hight |
---|---|
114 | 24 |
35 | 7 |
60 | 15 |
74 | 26 |
68 | 23 |
55 | 15 |
## [1] 4.750000 5.000000 4.000000 2.846154 2.956522 3.666667 2.812500 2.222222
## [9] 4.153846 2.294118 3.086957 4.588235 3.133333 3.153846 2.533333 2.750000
## [17] 3.333333 2.769231 2.722222 3.117647 8.533333 3.277778 3.142857 3.133333
## [25] 2.045455 3.533333 2.947368 2.600000 2.153846 6.111111
## [1] 4.750000 5.000000 4.000000 2.846154 2.956522 3.666667 2.812500 2.222222
## [9] 4.153846 2.294118 3.086957 4.588235 3.133333 3.153846 2.533333 2.750000
## [17] 3.333333 2.769231 2.722222 3.117647 8.533333 3.277778 3.142857 3.133333
## [25] 2.045455 3.533333 2.947368 2.600000 2.153846 6.111111
## [1] 4.750000 5.000000 4.000000 2.846154 2.956522 3.666667 2.812500 2.222222
## [9] 4.153846 2.294118 3.086957 4.588235 3.133333 3.153846 2.533333 2.750000
## [17] 3.333333 2.769231 2.722222 3.117647 8.533333 3.277778 3.142857 3.133333
## [25] 2.045455 3.533333 2.947368 2.600000 2.153846 6.111111
Assuming that the order of the a-entries, the b-entries and the c-entries is correct and that the different categories belong to three observations.
ai <- 1
bi <- 1
ci <- 1
for (i in 1:nrow(df)){
if (df$key[i] == "a") {
df2$a[ai] <- df$value[i]
ai <- ai + 1
}
if (df$key[i] == "b") {
df2$b[bi] <- df$value[i]
bi <- bi + 1
}
if (df$key[i] == "c") {
df2$c[ci] <- df$value[i]
ci <- ci + 1
}
}
df2
a | b | c |
---|---|---|
1 | 54 | 743 |
3 | 66 | 234 |
2 | 43 | 444 |