Professional Documents
Culture Documents
Vector
Vector
R Programming Code :
x = vector("numeric", 5)
print("Numeric Type:")
print(x)
c = vector("complex", 5)
print("Complex Type:")
print(c)
l = vector("logical", 5)
print("Logical Type:")
print(l)
chr = vector("character", 5)
print("Character Type:")
print(chr)
Sample Output:
[1] "Numeric Type:"
[1] 0 0 0 0 0
[1] "Complex Type:"
[1] 0+0i 0+0i 0+0i 0+0i 0+0i
[1] "Logical Type:"
[1] FALSE FALSE FALSE FALSE FALSE
[1] "Character Type:"
[1] "" "" "" "" ""
R Programming Code :
Sample Output:
Sample Output:
[1] "Sum:"
[1] 60
[1] "Mean:"
[1] 20
[1] "Product:"
[1] 6000
[1] 30 30 70
R Programming Code :
dfc1 = c(1, 2, 3, 4, 5)
dfc2 = c(6, 7, 8, 9, 10)
dfc3 = c(11, 12, 13, 14, 15)
dfc4 = c(16, 17, 18, 19, 20)
v <- data.frame(dfc1=1:5, dfc2=6:10, dfc3=11:15, dfc4=16:20)
print(v)
Sample Output:
5)Write a R program to add 3 to each element in a given vector. Print the original
and new vector.
R Programming Code :
Sample Output:
R Programming Code :
x = 1:15
print("New vector using : operator-")
print(x)
print("New vector using seq() function-")
print("Specify step size:")
y = seq(1, 3, by=0.3)
print(y)
print("Specify length of the vector:")
z = seq(1, 5, length.out = 6)
print(z)
Sample Output: