I am writing an if else statement that takes an input (tool, in the form of a barcode number) and outputs the tool name, and location.
I'm also writing it so that when a certain Barcode Number(tool) is input, it adds to the running total that I have in column name (TIMES.USED). I am having problems though because I am trying to add a check in/out column(Status), that basically reads that if an items usage value is divisible by 2, the item is checked in. If it is not divisible by 2, the item is checked out. Here is the structure of my data frame and the code that I have written so far:
Data Frame:
Barcode.Number, Type.Equipment, Manufacture, Times.Used, Status
4041, Flash Light, Surefire, 1
4044, Rope, Surefire, 2
Code:
tool = as.integer(readline(prompt="Enter a number: "))
df1 <- df %>% filter(df$Barcode.Number == tool) %>%
select(Type.Equipment, Manufacture)
if((df$TIMES.USED %% 2) == 0) {
df$Status <- 'In'
} else {
df$Status <- 'Out'
}
I can get it so that when I input a number like 4041, it can see that the 1 is odd and outputs 'out' into the Status column. The problem is that I'm not sure how to write it so that it outputs different status' into different rows because it just outputs into all of them. Thank you!