d <- read.csv(file = 'https://stats.dip.jp/01_ds/data/data_cleansing2_dirty_data.csv')
m <- as.matrix(d)
boxplot(m)

any(m < 0)
## [1] TRUE
any(abs(m) > 3*sd(m))
## [1] TRUE
jj <- 36:46
boxplot(m[, jj])

j <- 37
y <- m[, j]
barplot(height = y,
names.arg = 1:nrow(m))

ii <- 140:231
y <- m[ii, j]
barplot(height = y,
cex.names = 0.4,
names.arg = paste(ii, '\n(', y, ')'))

ii <- 194:206
y <- m[ii, j]
barplot(height = y,
cex.names = 0.4,
names.arg = paste(ii, '\n(', y, ')'))

m[200,j]
## V37
## -0.78
m[m<0]
## [1] -21.00 -0.78 -0.99 -0.68
sigma <- sd(m)
m[abs(m) > 4*sigma]
## [1] 22 -21 11
m.a <- NULL
for (j in 1:ncol(m))
{
for (i in 1:nrow(m))
{
if ( m[i, j] < 0 | m[i, j] > 4 * sigma )
{
cat('Row:', i, ', Col:', j, ', Value: ', m[i, j], fill = T)
m.a <- rbind(m.a, t(c(i, j, m[i, j])))
}
}
}
## Row: 39 , Col: 1 , Value: 22
## Row: 52 , Col: 1 , Value: -21
## Row: 91 , Col: 1 , Value: 11
## Row: 200 , Col: 37 , Value: -0.78
## Row: 521 , Col: 59 , Value: -0.99
## Row: 242 , Col: 100 , Value: -0.68
colnames(m.a) <- c('Row','Col','Value')
m.a
## Row Col Value
## [1,] 39 1 22.00
## [2,] 52 1 -21.00
## [3,] 91 1 11.00
## [4,] 200 37 -0.78
## [5,] 521 59 -0.99
## [6,] 242 100 -0.68
d <- read.csv(file = 'https://stats.dip.jp/01_ds/data/data_cleansing2_dirty_data_exercise.csv')
library(DT)
datatable(d)
boxplot(d)

any(d < 0)
## [1] TRUE
jj <- 36:46
boxplot(d[, jj])

j <- 37
y <- d[, j]
barplot(height = y,
names.arg = 1:nrow(d))

ii <- 140:231
y <- d[ii, j]
barplot(height = y,
cex.names = 0.4,
names.arg = paste(ii, '\n(', y, ')'))

ii <- 194:206
y <- d[ii, j]
barplot(height = y,
cex.names = 0.4,
names.arg = paste(ii, '\n(', y, ')'))

d[200, j]
## [1] 0.67
d[d < 0]
## [1] -42.00 -0.92 -0.55 -0.03
d.a <- NULL
for (j in 1:ncol(d))
{
for (i in 1:nrow(d))
{
if ( d[i, j] < 0 | d[i, j] > 4 * sigma )
{
cat('Row:', i, ', Col:', j, ', Value: ', d[i, j], fill = T)
d.a <- rbind(d.a, t(c(i, j, d[i, j])))
}
}
}
## Row: 2 , Col: 1 , Value: -42
## Row: 42 , Col: 1 , Value: 22
## Row: 99 , Col: 1 , Value: 111
## Row: 531 , Col: 27 , Value: -0.92
## Row: 675 , Col: 83 , Value: -0.55
## Row: 124 , Col: 85 , Value: -0.03