The data are CSV, but the column IDs are in the column before the data. There are a number of blank lines intersperced within the data.
Aidan indicates that the RSSI and Distance variables are the only important variables.
d <- 1
trial <- 2
dat <- read_csv("./AidanData/1m/Trial1.txt", col_names=FALSE) %>%
select(X6, X14, X16) %>%
rename(Rep = X6, RSSI = X14, Distance = X16) %>%
mutate(d = d, trial = trial)
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(dat)
## Rep RSSI Distance d trial
## Min. : 1.0 Min. :-42.50 Min. :0.5957 Min. :1 Min. :2
## 1st Qu.: 250.8 1st Qu.:-40.50 1st Qu.:0.7079 1st Qu.:1 1st Qu.:2
## Median : 500.5 Median :-40.00 Median :1.0000 Median :1 Median :2
## Mean : 500.5 Mean :-39.26 Mean :0.9406 Mean :1 Mean :2
## 3rd Qu.: 750.2 3rd Qu.:-37.00 3rd Qu.:1.0593 3rd Qu.:1 3rd Qu.:2
## Max. :1000.0 Max. :-35.50 Max. :1.3335 Max. :1 Max. :2
apply(dat,2,sd)
## Rep RSSI Distance d trial
## 288.8194361 1.9325024 0.1949482 0.0000000 0.0000000
d <- 2
trial <- 3
dat <- read_csv("./AidanData/2m/Trial5.txt", col_names=FALSE)%>%
select(X6, X14, X16) %>%
rename(Rep = X6, RSSI = X14, Distance = X16) %>%
mutate(d = d, trial = trial)
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(dat)
## Rep RSSI Distance d trial
## Min. :-47.00 Min. :1.122 Min. :0.000 Min. :2 Min. :3
## 1st Qu.:-47.00 1st Qu.:1.496 1st Qu.:0.000 1st Qu.:2 1st Qu.:3
## Median :-47.00 Median :1.679 Median :0.400 Median :2 Median :3
## Mean :-46.97 Mean :1.654 Mean :1.038 Mean :2 Mean :3
## 3rd Qu.:-47.00 3rd Qu.:1.778 3rd Qu.:1.913 3rd Qu.:2 3rd Qu.:3
## Max. :-44.00 Max. :1.995 Max. :7.614 Max. :2 Max. :3
## NA's :799
apply(dat,2,sd)
## Rep RSSI Distance d trial
## 0.2441282 0.2142756 NA 0.0000000 0.0000000
d <- 3
trial <- 4
dat <- read_csv("./AidanData/3m/Trial4.txt", col_names=FALSE) %>%
select(X6, X14, X16) %>%
rename(Rep = X6, RSSI = X14, Distance = X16) %>%
mutate(d = d, trial = trial)
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
summary(dat)
## Rep RSSI Distance d trial
## Min. : 1.0 Min. :-54.50 Min. :1.778 Min. :3 Min. :4
## 1st Qu.: 250.8 1st Qu.:-51.50 1st Qu.:2.371 1st Qu.:3 1st Qu.:4
## Median : 500.5 Median :-50.00 Median :2.818 Median :3 Median :4
## Mean : 500.5 Mean :-50.07 Mean :2.922 Mean :3 Mean :4
## 3rd Qu.: 750.2 3rd Qu.:-48.50 3rd Qu.:3.350 3rd Qu.:3 3rd Qu.:4
## Max. :1000.0 Max. :-46.00 Max. :4.732 Max. :3 Max. :4
apply(dat,2,sd)
## Rep RSSI Distance d trial
## 288.8194361 2.0733245 0.6925974 0.0000000 0.0000000
We work on the file names.
d <- 2
trial <- 7
(fn <- paste0("./AidanData/",d,"m/Trial",trial,".txt"))
## [1] "./AidanData/2m/Trial7.txt"
for (d in 1:3){
for (trial in 1:10){
fn <- paste0("./AidanData/",d,"m/Trial",trial,".txt")
print(fn)
}
}
## [1] "./AidanData/1m/Trial1.txt"
## [1] "./AidanData/1m/Trial2.txt"
## [1] "./AidanData/1m/Trial3.txt"
## [1] "./AidanData/1m/Trial4.txt"
## [1] "./AidanData/1m/Trial5.txt"
## [1] "./AidanData/1m/Trial6.txt"
## [1] "./AidanData/1m/Trial7.txt"
## [1] "./AidanData/1m/Trial8.txt"
## [1] "./AidanData/1m/Trial9.txt"
## [1] "./AidanData/1m/Trial10.txt"
## [1] "./AidanData/2m/Trial1.txt"
## [1] "./AidanData/2m/Trial2.txt"
## [1] "./AidanData/2m/Trial3.txt"
## [1] "./AidanData/2m/Trial4.txt"
## [1] "./AidanData/2m/Trial5.txt"
## [1] "./AidanData/2m/Trial6.txt"
## [1] "./AidanData/2m/Trial7.txt"
## [1] "./AidanData/2m/Trial8.txt"
## [1] "./AidanData/2m/Trial9.txt"
## [1] "./AidanData/2m/Trial10.txt"
## [1] "./AidanData/3m/Trial1.txt"
## [1] "./AidanData/3m/Trial2.txt"
## [1] "./AidanData/3m/Trial3.txt"
## [1] "./AidanData/3m/Trial4.txt"
## [1] "./AidanData/3m/Trial5.txt"
## [1] "./AidanData/3m/Trial6.txt"
## [1] "./AidanData/3m/Trial7.txt"
## [1] "./AidanData/3m/Trial8.txt"
## [1] "./AidanData/3m/Trial9.txt"
## [1] "./AidanData/3m/Trial10.txt"
Now, make the tibble creation a function and merge all the inputted files.
read_trial_file <- function(d, trial){
fn <- paste0("./AidanData/",d,"m/Trial",trial,".txt")
if (d == 2){
dat <- read_csv(file=fn, col_names=FALSE) %>%
select(X4, X12, X14) %>%
rename(Rep = X4, RSSI = X12, Distance = X14) %>%
mutate(d = d, trial = trial)
}else{
dat <- read_csv(file=fn, col_names=FALSE) %>%
select(X6, X14, X16) %>%
rename(Rep = X6, RSSI = X14, Distance = X16) %>%
mutate(d = d, trial = trial)
}
return(dat)
}
### Check it
d <- 3
trial <- 5
dat <- read_trial_file(d, trial)
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(dat)
## # A tibble: 6 × 5
## Rep RSSI Distance d trial
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 -51 3.16 3 5
## 2 2 -51 3.16 3 5
## 3 3 -49.5 2.66 3 5
## 4 4 -49.5 2.66 3 5
## 5 5 -49.5 2.66 3 5
## 6 6 -49.5 2.66 3 5
Now read it all.
### Read them all
prt <- FALSE
for (d in 1:3){
for (trial in 1:10){
if (d==1 & trial==1){
dat <- read_trial_file(1, 1)
if (prt) {
print(summary(dat))
}
}else{
tmp <- read_trial_file(d, trial)
if (prt){
print(summary(tmp))
}
dat <- rbind(dat, tmp)
}
}
}
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 20
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (11): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19
## dbl (9): X4, X6, X8, X10, X12, X14, X16, X18, X20
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
## Rows: 1000 Columns: 22
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (12): X1, X2, X3, X5, X7, X9, X11, X13, X15, X17, X19, X21
## dbl (10): X4, X6, X8, X10, X12, X14, X16, X18, X20, X22
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
dim(dat)
## [1] 30000 5
Look at what’s in it.
dat %>% group_by(d) %>%
summarize(xbar_RSSI = mean(RSSI), sd_RSSI = sd(RSSI), xbar_dist = mean(Distance), sd_dist = sd(Distance))
## # A tibble: 3 × 5
## d xbar_RSSI sd_RSSI xbar_dist sd_dist
## <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 1 -39.6 2.22 0.983 0.232
## 2 2 -45.2 1.19 1.64 0.215
## 3 3 -50.0 2.12 2.89 0.713
dat %>% group_by(d, trial) %>%
summarize(xbar_RSSI = mean(RSSI), sd_RSSI = sd(RSSI), xbar_dist = mean(Distance), sd_dist = sd(Distance)) %>%
ggplot(aes(x=xbar_RSSI, y=sd_RSSI)) + geom_point()
## `summarise()` has grouped output by 'd'. You can override using the `.groups`
## argument.
dat %>% ggplot(aes(x=factor(d), y=Distance)) + geom_violin(fill="cyan") + geom_boxplot(width=0.02)