Reputation: 45
In python, the function input is used along with an assignment to a variable. I have code where I am assigning the input of the user to the variables outcome and state, but R will not take the function. What is the equivalent of this in R and please show an example.
best <- function(state, outcome) {
#read file function
dataTable <- read.csv("outcome.csv", header = TRUE)
choice <- state
stateOfChoice <- dataTable[which(dataTable$state == choice),]
if (outcome == "heart attack"){
#subsetting,selecting column of "Lower mortality estimate [xxxSpecified Outcomexxx ]" & the Hospital name attach to it
heart_attack <- outcome[which.min(outcome$Lower.Mortality.Estimate...Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack),]
name <- heart_attack$state
hospital <- heart_attack$Hospital.Name
}
return(hospital)
}
main <- function() {
print("Type Heart Attack, .....")
outcome <- input("Type your selection")
print("Select state")
state <- input("Type in your selection")
best(state,outcome)
}
main()
Upvotes: 0
Views: 1426
Reputation: 616
In R, this would be readline.
e.g.
> name <- readline(prompt="Enter name: ")
Enter name: Blah Blah
> paste0(name)
[1] "Blah Blah"
Upvotes: 5