Basic data operations in R
IntroductionIn this article we provide a presentation that describes how to obtain a fast overview of the (normal size) data. Note that all these examples assume that you have
rstudio &in the terminal) and
- you have opened a new
ctrl+shift+nyou start a new script file that you have to save first to a local folder. Once you type (copy) the
Rcode into the script file, you run it by, e.g., selecting the part of the code you want to run and typing
Suppose we have a data frame containing 3 numerical ratio variables and 1 categorical variable
M1 <- matrix(rnorm(150,0,1), ncol=3)
M2 <- matrix(round(runif(50,1,4),0),ncol=1)
M3 <- mapvalues(M2, from = 1:4, to = group)
Descriptive statisticsIf you want to see the distribution (frequencies) of the different category values for the variable
group(we address it as
M$group) you should use
Group_A Group_B Group_D Group_E
10 14 20 6
M(the centroid) and the group centroids for these columns, where the groups are defined by
group. Here is the code and the results.
centr=colMeans(M[,1:3]) # CENTROID
X1 X2 X3
-0.15863016 0.19138859 0.06853306
aggregate(M[,1:3],by=list(M$group),FUN=mean) # GROUP CENTROIDS
group X1 X2 X3
1 Group_A -0.1159164 0.187124494 0.51985248
2 Group_B -0.1770462 0.532357620 -0.16423459
3 Group_D -0.1651467 0.013811050 0.06511391
4 Group_E -0.1651271 -0.005173836 -0.12914429
Managing Big Data with R and Hadoop
Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.