Read data into R.

classes <- read.csv("class.csv", stringsAsFactors = T)

Check the structure of the data frame.

str(classes)
## 'data.frame':    26 obs. of  40 variables:
##  $ Timestamp                                                                                    : Factor w/ 26 levels "25/09/2017 08:59:41",..: 1 2 3 4 5 6 7 8 9 10 ...
##  $ X1..Voting.in.general.elections.should.be.made.compulsory..like.in.Australia..               : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 1 1 1 1 1 2 ...
##  $ X2..Maid.cafés.are.a.benefit.to.Japanese.culture.                                            : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 1 1 1 2 1 2 ...
##  $ X3..There.s.nothing.wrong.with.talking.on.a.mobile.phone.on.buses.or.trains.                 : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 2 2 2 2 2 2 2 ...
##  $ X4..Japan.s.govt..should.not.force.teachers.to.sing.the.kimigayo.and.raise.the.hinomaru.     : Factor w/ 2 levels "I agree.","I disagree.": 2 1 2 2 2 2 2 2 1 1 ...
##  $ X5..In.Japan.today..most.people.don.t.need.English.                                          : Factor w/ 1 level "I disagree.": 1 1 1 1 1 1 1 1 1 1 ...
##  $ X6..Testing.on.animals..for.cosmetics...medicines.etc...should.be.banned.                    : Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 2 1 2 2 1 1 ...
##  $ X7..College.students.should.experience.living.by.themselves.                                 : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 1 1 2 1 2 2 ...
##  $ X8..Smoking.in.all.public.places.should.be.banned.                                           : Factor w/ 2 levels "I agree.","I disagree.": 2 1 1 1 1 1 1 1 1 1 ...
##  $ X9..The.hours.a.college.student.can.work.part.time.should.be.limited.                        : Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 2 2 1 1 2 2 ...
##  $ X10..School.uniforms.are.unnecessary.                                                        : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 2 2 2 2 1 1 2 ...
##  $ X11..It.s.more.useful.to.learn.Chinese.than.English.as.a.second.language.                    : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 1 2 2 2 2 2 2 ...
##  $ X12..People.in.Japan.who.drop.litter.should.be.fined.                                        : Factor w/ 2 levels "I agree.","I disagree.": 1 2 2 1 1 2 2 1 2 1 ...
##  $ X13..Japan.should.close.all.its.nuclear.power.plants.                                        : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 2 2 1 1 1 1 ...
##  $ X14..Japan.needs.to.develop.new.nuclear.power.plants.to.meet.the.demand.for.electricity.     : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 2 1 2 1 1 2 1 ...
##  $ X15..The.AO.and.recommendation.system.of.entering.university.should.be.abolished.            : Factor w/ 2 levels "I agree.","I disagree.": 2 1 2 2 2 2 2 2 1 2 ...
##  $ X16..PTAs.are.not.necessary.for.high.schools.                                                : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 1 2 1 1 1 1 1 ...
##  $ X17..It.s.more.interesting.to.watch.movies.made.from.novels.than.to.read.the.original.novels.: Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 1 2 1 1 2 2 ...
##  $ X18..The.age.that.Japanese.can.drink.alcohol.should.be.lowered.from.20.to.18.years.old.      : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 1 2 2 1 1 1 2 ...
##  $ X19..People.should.be.allowed.to.vote.at.the.age.of.18.                                      : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 2 1 2 1 1 1 ...
##  $ X20..Same.sex.marriage.should.be.allowed.everywhere.                                         : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 2 1 1 1 1 1 ...
##  $ X21..Co.educational.schools.are.better.than.women.only.schools.for.students.                 : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 1 1 1 1 1 2 1 ...
##  $ X22..Every.college.and.university.should.have.a.sports.festival.                             : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 2 2 1 1 2 1 2 ...
##  $ X23..High.school.education.should.be.compulsory.                                             : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 1 1 1 1 1 1 1 ...
##  $ X24..High.school.students.shouldn.t.bring.their.mobile.phones.to.school.                     : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 2 2 2 2 2 2 1 ...
##  $ X25..The.age.that.Japanese.can.get.a.drivers.license.should.be.lowered.to.16.                : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 2 2 2 2 1 2 2 ...
##  $ X26..The.government.should.re.introduce.the.6.days.school.week.                              : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 2 1 2 2 2 2 2 ...
##  $ X27..Using.a.paper.dictionary.is.better.than.an.electronic.dictionary.                       : Factor w/ 2 levels "I agree.","I disagree.": 2 2 1 2 2 1 2 2 1 2 ...
##  $ X28..Learning.a.second.language.at.elementary.school.age.is.too.early.                       : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 2 1 2 2 2 2 2 ...
##  $ X29..It.is.better.to.get.married.when.you.are.over.27.                                       : Factor w/ 2 levels "I agree.","I disagree.": 2 1 1 2 1 1 1 2 1 2 ...
##  $ X30..The.government.should.change.the.law.so.that.people.become.adult.at.18.years.old.       : Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 2 2 2 1 2 2 ...
##  $ X31..Women.only.carriages.on.trains.should.be.in.operation.all.day.                          : Factor w/ 2 levels "I agree.","I disagree.": 1 1 1 2 2 1 2 2 1 2 ...
##  $ X32..East.Asian.countries.should.have.a.common.currency.like.the.euro.in.Europe.             : Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 1 2 2 2 1 2 ...
##  $ X33..Japan.should.change.article.9.and.have.a.normal.military.                               : Factor w/ 2 levels "I agree.","I disagree.": 1 2 2 2 2 2 2 1 1 2 ...
##  $ X34..Japan.s.consumption.tax.should.be.increased.to.15..                                     : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 2 2 2 2 2 2 2 ...
##  $ X35..Japan.should.be.stronger.in.its.relations.with.China.                                   : Factor w/ 2 levels "I agree.","I disagree.": 1 2 1 1 1 2 2 1 1 2 ...
##  $ X36..The.death.penalty.should.be.abolished.                                                  : Factor w/ 2 levels "I agree.","I disagree.": 2 2 2 1 2 2 2 2 1 2 ...
##  $ X37..The.law.of.limitations.on.a.crime.should.be.abolished.                                  : Factor w/ 2 levels "I agree.","I disagree.": 1 1 2 2 2 1 2 2 2 2 ...
##  $ Name                                                                                         : Factor w/ 26 levels "Kana","Kaori",..: 18 12 23 7 20 4 2 21 1 14 ...
##  $ Which.class.are.you.in.                                                                      : Factor w/ 2 levels "Period 1 (8:50am to 10:20am)",..: 1 1 1 1 1 1 1 1 1 1 ...

Convert text strings “I agree.” to ones, and “I disagree.” to zeros.

classes <- as.data.frame(sapply(classes, function(x) gsub("I agree.", 1, x)))
classes <- as.data.frame(sapply(classes, function(x) gsub("I disagree.", 0, x)))

Convert character ones and zeros to numerics.

classes[,2:38] <- lapply(classes[,2:38], as.numeric) 

Make students’ names the row names.

row.names(classes) <- classes$Name

Get rid of column variable for students’ names.

classes$Name <- NULL

Subset data for each class.

period_1 <- classes %>% filter(Which.class.are.you.in. == "Period 1 (8:50am to 10:20am)")
period_2 <- classes %>% filter(Which.class.are.you.in. == "Period 2 (10:30am to 12pm)")

Delete “Which class are you in?” variable.

period_1$Which.class.are.you.in. <- NULL
period_2$Which.class.are.you.in. <- NULL

Check the structure of one of these classes.

str(period_1)
## 'data.frame':    11 obs. of  38 variables:
##  $ Timestamp                                                                                    : chr  "25/09/2017 08:59:41" "25/09/2017 09:03:37" "25/09/2017 09:04:12" "25/09/2017 09:04:20" ...
##  $ X1..Voting.in.general.elections.should.be.made.compulsory..like.in.Australia..               : num  1 1 1 1 1 1 1 1 1 0 ...
##  $ X2..Maid.cafés.are.a.benefit.to.Japanese.culture.                                            : num  1 1 1 1 1 1 1 0 1 0 ...
##  $ X3..There.s.nothing.wrong.with.talking.on.a.mobile.phone.on.buses.or.trains.                 : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ X4..Japan.s.govt..should.not.force.teachers.to.sing.the.kimigayo.and.raise.the.hinomaru.     : num  0 1 0 0 0 0 0 0 1 1 ...
##  $ X5..In.Japan.today..most.people.don.t.need.English.                                          : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ X6..Testing.on.animals..for.cosmetics...medicines.etc...should.be.banned.                    : num  1 0 1 1 0 1 0 0 1 1 ...
##  $ X7..College.students.should.experience.living.by.themselves.                                 : num  1 1 1 1 1 1 0 1 0 0 ...
##  $ X8..Smoking.in.all.public.places.should.be.banned.                                           : num  0 1 1 1 1 1 1 1 1 1 ...
##  $ X9..The.hours.a.college.student.can.work.part.time.should.be.limited.                        : num  1 0 1 1 0 0 1 1 0 0 ...
##  $ X10..School.uniforms.are.unnecessary.                                                        : num  0 0 1 0 0 0 0 1 1 0 ...
##  $ X11..It.s.more.useful.to.learn.Chinese.than.English.as.a.second.language.                    : num  0 0 1 1 0 0 0 0 0 0 ...
##  $ X12..People.in.Japan.who.drop.litter.should.be.fined.                                        : num  1 0 0 1 1 0 0 1 0 1 ...
##  $ X13..Japan.should.close.all.its.nuclear.power.plants.                                        : num  1 1 1 1 0 0 1 1 1 1 ...
##  $ X14..Japan.needs.to.develop.new.nuclear.power.plants.to.meet.the.demand.for.electricity.     : num  0 0 1 0 1 0 1 1 0 1 ...
##  $ X15..The.AO.and.recommendation.system.of.entering.university.should.be.abolished.            : num  0 1 0 0 0 0 0 0 1 0 ...
##  $ X16..PTAs.are.not.necessary.for.high.schools.                                                : num  0 0 0 1 0 1 1 1 1 1 ...
##  $ X17..It.s.more.interesting.to.watch.movies.made.from.novels.than.to.read.the.original.novels.: num  1 0 1 1 1 0 1 1 0 0 ...
##  $ X18..The.age.that.Japanese.can.drink.alcohol.should.be.lowered.from.20.to.18.years.old.      : num  0 0 1 1 0 0 1 1 1 0 ...
##  $ X19..People.should.be.allowed.to.vote.at.the.age.of.18.                                      : num  1 1 1 1 0 1 0 1 1 1 ...
##  $ X20..Same.sex.marriage.should.be.allowed.everywhere.                                         : num  1 1 1 1 0 1 1 1 1 1 ...
##  $ X21..Co.educational.schools.are.better.than.women.only.schools.for.students.                 : num  0 0 1 1 1 1 1 1 0 1 ...
##  $ X22..Every.college.and.university.should.have.a.sports.festival.                             : num  0 0 1 0 0 1 1 0 1 0 ...
##  $ X23..High.school.education.should.be.compulsory.                                             : num  1 1 1 1 1 1 1 1 1 1 ...
##  $ X24..High.school.students.shouldn.t.bring.their.mobile.phones.to.school.                     : num  0 0 1 0 0 0 0 0 0 1 ...
##  $ X25..The.age.that.Japanese.can.get.a.drivers.license.should.be.lowered.to.16.                : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ X26..The.government.should.re.introduce.the.6.days.school.week.                              : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ X27..Using.a.paper.dictionary.is.better.than.an.electronic.dictionary.                       : num  0 0 1 0 0 1 0 0 1 0 ...
##  $ X28..Learning.a.second.language.at.elementary.school.age.is.too.early.                       : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ X29..It.is.better.to.get.married.when.you.are.over.27.                                       : num  0 1 1 0 1 1 1 0 1 0 ...
##  $ X30..The.government.should.change.the.law.so.that.people.become.adult.at.18.years.old.       : num  1 0 1 1 0 0 0 1 0 0 ...
##  $ X31..Women.only.carriages.on.trains.should.be.in.operation.all.day.                          : num  1 1 1 0 0 1 0 0 1 0 ...
##  $ X32..East.Asian.countries.should.have.a.common.currency.like.the.euro.in.Europe.             : num  1 0 1 1 1 0 0 0 1 0 ...
##  $ X33..Japan.should.change.article.9.and.have.a.normal.military.                               : num  1 0 0 0 0 0 0 1 1 0 ...
##  $ X34..Japan.s.consumption.tax.should.be.increased.to.15..                                     : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ X35..Japan.should.be.stronger.in.its.relations.with.China.                                   : num  1 0 1 1 1 0 0 1 1 0 ...
##  $ X36..The.death.penalty.should.be.abolished.                                                  : num  0 0 0 1 0 0 0 0 1 0 ...
##  $ X37..The.law.of.limitations.on.a.crime.should.be.abolished.                                  : num  1 1 0 0 0 1 0 0 0 0 ...

Calculate the Euclidean distances between each student based on their answers to the social issues questionnaire. Then plot the dendrogram.

period_1 %>% dist %>% hclust %>% plot
## Warning in dist(.): NAs introduced by coercion

period_2 %>% dist %>% hclust %>% plot
## Warning in dist(.): NAs introduced by coercion

The students are now clustered according to their social values. In a previous lesson, they had delivered balanced presentations. Now they can be persuasive about an issue that concerns them.