1# take input from the user
2num = as.integer(readline(prompt="Enter a number: "))
4# check is the number is negative, positive or zero
6print("Sorry, factorial does not exist for negative numbers")
8print("The factorial of 0 is 1")
11factorial = factorial * i
13print(paste("The factorial of", num ,"is",factorial))
18print("Negative number")
20print("Positive number")
41`%divisible%` <- function(x,y)
43if (x%%y ==0) return (TRUE)
47switch("length", "color" = "red", "shape" = "square", "length" = 5)
50recursive.factorial <- function(x) {
52else return (x * recursive.factorial(x-1))
55pow <- function(x, y) {
56# function to print x raised to the power y
58print(paste(x,"raised to the power", y, "is", result))
61A <- read.table("x.data", sep=",",
62 col.names=c("year", "my1", "my2"))
63nrow(A) # Count the rows in A
67A$newcol <- A$my1 + A$my2 # Makes a new
68newvar <- A$my1 - A$my2 # Makes a
69A$my1 <- NULL # Removes
76set.seed(102) # This yields a good illustration.
77x <- sample(1:3, 15, replace=TRUE)
78education <- factor(x, labels=c("None", "School", "College"))
79x <- sample(1:2, 15, replace=TRUE)
80gender <- factor(x, labels=c("Male", "Female"))
81age <- runif(15, min=20,max=60)
83D <- data.frame(age, gender, education)
84rm(x,age,gender,education)
87# Table about education
90# Table about education and gender --
91table(D$gender, D$education)
92# Joint distribution of education and gender --
93table(D$gender, D$education)/nrow(D)
95# Add in the marginal distributions also
96addmargins(table(D$gender, D$education))
97addmargins(table(D$gender, D$education))/nrow(D)
99# Generate a good LaTeX table out of it --
101xtable(addmargins(table(D$gender, D$education))/nrow(D),
104by(D$age, D$gender, mean)
105by(D$age, D$gender, sd)
106by(D$age, D$gender, summary)
108a <- matrix(by(D$age, list(D$gender, D$education), mean), nrow=2)
109rownames(a) <- levels(D$gender)
110colnames(a) <- levels(D$education)
114dat <- read.csv(file = "files/dataset-2013-01.csv", header = TRUE)
115interim_object <- data.frame(rep(1:100, 10),
118object.size(interim_object)
124vector2 <- c(10,11,12,13,14,15)
125array1 <- array(c(vector1,vector2),dim = c(3,3,2))
127vector4 <- c(6,0,11,3,14,1,2,6,9)
128array2 <- array(c(vector1,vector2),dim = c(3,3,2))
129matrix1 <- array1[,,2]
130matrix2 <- array2[,,2]
131result <- matrix1+matrix2
134column.names <- c("COL1","COL2","COL3")
135row.names <- c("ROW1","ROW2","ROW3")
136matrix.names <- c("Matrix1","Matrix2")
137result <- array(c(vector1,vector2),dim = c(3,3,2),dimnames = list(row.names,
138 column.names, matrix.names))
143# Load the package required to read JSON files.
145result <- fromJSON(file = "input.json")
148x <- c(151, 174, 138, 186, 128, 136, 179, 163, 152, 131)
149y <- c(63, 81, 56, 91, 47, 57, 76, 72, 62, 48)
154png(file = "linearregression.png")
155plot(y,x,col = "blue",main = "Height & Weight Regression",
156abline(lm(x~y)),cex = 1.3,pch = 16,xlab = "Weight in Kg",ylab = "Height in cm")
159data <- c("East","West","East","North","North","East","West","West","West","East","North")
161print(is.factor(data))
162factor_data <- factor(data)
164print(is.factor(factor_data))
168# Give the chart file a name.
169png(file = "line_chart_label_colored.jpg")
170plot(v,type = "o", col = "red", xlab = "Month", ylab = "Rain fall", main = "Rain fall chart")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list