NEP -R PROGRAMMING

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6 PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10

PART B

PROGRAM B1 PROGRAM B2 PROGRAM B3 PROGRAM B4 PROGRAM B5 PROGRAM B6 PROGRAM B7 PROGRAM B8 . . .

 
   
 
 
 #Write an R program for different types of data structures in R.


#  array--------------

A = array(
	# Taking sequence of elements
	c(1, 2, 3, 4, 5, 6, 7, 8),

	# Creating two rectangular matrices 
	# each with two rows and two columns
	dim = c(2, 2, 2)					 
)

print(A)


#  matrix-------------------

A = matrix(
	# Taking sequence of elements
	c(1, 2, 3, 4, 5, 6, 7, 8, 9), 
	
	# No of rows and columns
	nrow = 3, ncol = 3, 

	 	 
	byrow = TRUE							 
)

print(A)


#   Vector------------------

# Vectors(ordered collection of same data type)
X = c(1, 3, 5, 7, 8)

# Printing those elements in console
print(X)



#  List----------------

 
empId = c(1, 2, 3, 4)

 
empName = c("Debi", "Sandeep", "Subham", "Shiba")

# The third attribute is the number of employees
# which is a single numeric variable.
numberOfEmp = 4

 
empList = list(empId, empName, numberOfEmp)

print(empList)



# dataframe

# A vector which is a character vector
Name = c("Amiya", "Raj", "Asish")

# A vector which is a character vector
Language = c("R", "Python", "Java")

# A vector which is a numeric vector
Age = c(22, 25, 45)

 
df = data.frame(Name, Language, Age)

print(df)

#   factors-------------

# Creating factor using factor()
fac = factor(c("Male", "Female", "Male",
			"Male", "Female", "Male", "Female"))

print(fac)