saving . . . saved Functions has been deleted. Functions has been hidden .
Functions
Title
Question
Create a function to create an employee data frame (Name,Gender,Age,Designation & SSN). Function should return the dataframe employee. In main R script print Name and Age of employees.

R Functions-in-R 03-04 min 40-50 sec 02-05-20, 12:56 a.m. SUBHO98

Answers:

Please refer to the tutorial Introduction to Data Frames in R for getting insights on data frames. 
02-05-20, 1:04 a.m. sudhakarst
I have created the data frame but the issue is with function. I am showing my code :

employee <- data.frame("Name","Gender","Age","Designation","SSN")
emp <- function(employee){
  Name <- as.character(readline("Enter name: "))
  Gender <- as.character(readline("Enter gender: "))
  Age <- as.integer(readline("Enter age: "))
  Designation <- as.character(readline("Enter designation: "))
  SSN <- as.integer(readline("Enter SSN: "))
}
return(emp)
emp()

View(employee)


I can not get my answer.

02-05-20, 1:18 a.m. SUBHO98
You can try something as given below: 

employee <- data.frame(Name = character(), Gender = character(),
                       Age = numeric(), Designation = character(),
                       SSN = numeric())

emp <- function(){
  Name <- as.character(readline("Enter name: "))
  Gender <- as.character(readline("Enter gender: "))
  Age <- as.integer(readline("Enter age: "))
  Designation <- as.character(readline("Enter designation: "))
  SSN <- as.integer(readline("Enter SSN: "))
  return(data.frame(Name, Gender, Age, Designation, SSN))
}

newentry <- emp()
employee <- rbind(employee, newentry)
View(employee)
02-05-20, 2:08 a.m. sudhakarst

Login to add comment


Log-in to answer to this question.