Title: Balance Scale Weight & Distance Database.

# load data from url
balance_scale_data <- read.csv("https://archive.ics.uci.edu/ml/machine-learning-databases/balance-scale/balance-scale.data", header = TRUE, sep = ",");

#load library plyr (if you dont have it, install it).

library(plyr);

# A glance at the data and it structure.

View(balance_scale_data);
head(balance_scale_data);
##   B X1 X1.1 X1.2 X1.3
## 1 R  1    1    1    2
## 2 R  1    1    1    3
## 3 R  1    1    1    4
## 4 R  1    1    1    5
## 5 R  1    1    2    1
## 6 R  1    1    2    2
str(balance_scale_data);
## 'data.frame':    624 obs. of  5 variables:
##  $ B   : Factor w/ 3 levels "B","L","R": 3 3 3 3 3 3 3 3 3 3 ...
##  $ X1  : int  1 1 1 1 1 1 1 1 1 1 ...
##  $ X1.1: int  1 1 1 1 1 1 1 1 1 1 ...
##  $ X1.2: int  1 1 1 1 2 2 2 2 2 3 ...
##  $ X1.3: int  2 3 4 5 1 2 3 4 5 1 ...
# Setting the data frame to Factor.

data <- as.data.frame(lapply(balance_scale_data,function (y) if(class(y)=="factor" ) as.character(y) else y),stringsAsFactors=F);

# changing the data columns name. (altering the data.frame for easy accesibility)

balance_data=rename(data, c("B"="classname", "X1"="leftweight ", "X1.1"="leftdistances ", "X1.2"="rightweight ", "X1.3"="rightdistances"));

# We now change the row variable.


# CLASSNAME COLUMN:

balance_data$classname[balance_data$classname == "R"] <- "right";
balance_data$classname[balance_data$classname == "L"] <- "left";
balance_data$classname[balance_data$classname == "B"] <- "balance";

# LEFT-WEIGHT COLUMN

balance_data$`leftweight `[balance_data$`leftweight ` == "1"] <- "lightweight";
balance_data$`leftweight `[balance_data$`leftweight ` == "2"] <- "small";
balance_data$`leftweight `[balance_data$`leftweight ` == "3"] <- "mid-heavy";
balance_data$`leftweight `[balance_data$`leftweight ` == "4"] <- "mini-heavy";
balance_data$`leftweight `[balance_data$`leftweight ` == "5"] <- "heavy";


# LEFT DISTANCE
balance_data$`leftdistances`[balance_data$`leftdistances ` == "1"] <- "far";
balance_data$`leftdistances`[balance_data$`leftdistances ` == "2"] <- "not-too-far";
balance_data$`leftdistances`[balance_data$`leftdistances ` == "3"] <- "near";
balance_data$`leftdistances`[balance_data$`leftdistances ` == "4"] <- "nearer";
balance_data$`leftdistances`[balance_data$`leftdistances ` == "5"] <- "nearest";

# RIGHT-WEIGHT COLUMN
balance_data$`rightweight`[balance_data$`rightweight` == "1"] <- "lightweight";
balance_data$`rightweight`[balance_data$`rightweight` == "2"] <- "small";
balance_data$`rightweight`[balance_data$`rightweight` == "3"] <- "mid-heavy";
balance_data$`rightweight`[balance_data$`rightweight` == "4"] <- "mini-heavy";
balance_data$`rightweight`[balance_data$`rightweight` == "5"] <- "heavy";




# RIGHT-DISTANCES
balance_data$`rightdistances`[balance_data$`rightdistances` == "5"] <- "nearest";
balance_data$`rightdistances`[balance_data$`rightdistances` == "4"] <- "nearer";
balance_data$`rightdistances`[balance_data$`rightdistances` == "3"] <- "near";
balance_data$`rightdistances`[balance_data$`rightdistances` == "2"] <- "not-too-far";
balance_data$`rightdistances`[balance_data$`rightdistances` == "1"] <- "far";


View(balance_data[,-(5:3)]);
utils::View(balance_data[,-(5:3)]);

# SOME INFERENCES.

count(balance_data$leftweight);
##             x freq
## 1       heavy  125
## 2 lightweight  124
## 3   mid-heavy  125
## 4  mini-heavy  125
## 5       small  125
count(balance_data$rightweight);
##             x freq
## 1       heavy  125
## 2 lightweight  124
## 3   mid-heavy  125
## 4  mini-heavy  125
## 5       small  125

Source Information: (a) Source: Generated to model psychological experiments reported by Siegler, R. S. (1976). Three Aspects of Cognitive Development. Cognitive Psychology, 8, 481-520. (b) Donor: Tim Hume (hume@ics.uci.edu) (c) Date: 22 April 1994.

```