Data Visualisation L9+L10 Lab 1 R Basics: Printing Character
Data Visualisation L9+L10 Lab 1 R Basics: Printing Character
L9+L10
Lab 1
R Basics
PRINTING CHARACTER
print("Hello World")
[1] "Hello World"
print(23.9+56.6)
[1] 80.5
mystring<-"Hello World!"
print(mystring)
[1] "Hello World!"
PRINTING BOOLEAN
v <- TRUE
print(class(v)) #class function tells category of
the input
[1] "logical"
PRINTING COMPLEX
a<- 3+2i
print(class(a))
[1] "complex"
PRINTING INTEGER
i <- 253L
print(class(i))
[1] "integer"
VECTOR CHARACTER
vectora<-c('red','orange','kyoto')
print(vectora)
[1] "red" "orange" "kyoto"
print(class(vectora))
[1] "character"
VECTOR NUMERIC
vectorb<-c(1,2,3,4.5) #Here it shows
numeric instead of
integer because we have
included a decimal as
well
print(class(vectorb))
[1] "numeric"
VECTOR LOGICAL
vectorc<-c(TRUE,FALSE,TRUE,TRUE)
print(class(vectorc))
[1] "logical"
VECTOR RAW
vectord<-c(charToRaw("My Name is Anthony
Gonsalves!"),charToRaw("Why This Kolaveri
D"))
print(class(vectord)) #charToRaw converts to
hex value
[1] "raw"
v<-charToRaw("My Name is Akhil")
print(v)
[1] 4d 79 20 4e 61 6d 65 20 69 73 20 41 6b 68
69 6c
#hex value for space is
20
[[2]]
[1] 4
[[3]]
function (x) .Primitive("cos")
[[1]][[2]]
[1] 4
[[1]][[3]]
function (x) .Primitive("cos")
[[2]]
[[2]][[1]]
[1] 1
[[2]][[2]]
[1] 2
[[2]][[3]]
[1] 3
[[2]][[4]]
function (x) .Primitive("sin")
MATRIX
mat = matrix(c('a','b','c','d'),nrow = 2, ncol
=2,byrow = TRUE)
#matrix() function converts the list
given in c() to a matrix with
the help of specifiers nrow and ncol
and the byrow variable.
mat
[,1] [,2]
[1,] "a" "b"
[2,] "c" "d"
print(mat)
[,1] [,2]
[1,] "a" "b"
[2,] "c" "d"
print(class(mat)
+)
[1] "matrix"
ARRAY
arr <- array(c('green','potato'),dim = c(3,3,2))
#using c() to create an array with dim
specifier that specifies the number
of dimensions and elements in
those dimensions. Then the list in c() is
scaled and mapped accros all points
in the dimensions.
print(arr)
,,1
,,2
,,2
print(class(arr))
[1] "array"
DATA FRAMES
BMI<- data.frame(
+ gender = c("Male","Female","Male"),
+ height = c(152,146,133),
+ weight = c(233,343,112),
+ age = c(34,56,12))
#Organising data in a table
using frame
BMI
OUTPUT:
gender height weight age
1 Male 152 233 34
2 Female 146 343 56
3 Male 133 112 12
VARIABLES
var.1 = c(1,2,3,4)
.var2 = c("Akhil","Tripathi")
c(FALSE,0) -var3.
print(var.1)
[1] 1 2 3 4
cat("var.1 is ",var.1,"\n")
var.1 is 1 2 3 4
cat(".var2 is ",.var2,"\n")
.var2 is Akhil Tripathi
cat("var3. is ",var3.,"\n") #Trying diff naming
methods