[datatable-help] Classify User Input with Unique Identification Numbers
affableambler
nfields at gmail.com
Sun Jul 3 21:57:49 CEST 2016
I'm somewhat new to R and am trying to create a function that will take user
Input into a data frame, assign a new ID number to entries with new names,
and give the same ID number to inputs with the same name.
I wrote the following code:
options(stringsAsFactors = FALSE)
DbUpdate <- function(dataframe){
newline=c()
newline$Machine_Name=readline("Machine Name: ")
newline$Bet=as.double(readline("Bet: "))
newline$Return=as.double(readline("Return: "))
if(newline$Machine_Name %in% dataframe$Machine_Name)
{newline$MachineID=dataframe$MachineID[which(dataframe$Machine_Name %in%
newline$Machine_Name)]}
else(newline$MachineID=sample(100:999,1,replace=T))
dataframe=rbind(dataframe,newline,make.row.names=F)
return(data.frame(dataframe))
}
data=data.frame()
data=DbUpdate(data)
It works for the first two entries I put in with the same Machine_Name, but
when I try to input a third with the same name, I get an "Invalid list
argument: all variables should have the same length" error.
Can anyone tell me what I'm doing wrong?
--
View this message in context: http://r.789695.n4.nabble.com/Classify-User-Input-with-Unique-Identification-Numbers-tp4722458.html
Sent from the datatable-help mailing list archive at Nabble.com.
More information about the datatable-help
mailing list