vendredi 17 juillet 2020

How to create a new column with condition based on a column in data frame

result1 = data.frame(result, fin = "")

w=function(s){
for (i in s){
if(i in %in% c(S,T)){
if (result1 %in% 0:10) {
    fin <- c("J", "Z", "I", "H", "G", "F", "E", "D", "C", "B", "A")[result+1]
  } else {
    print("IC is Invalid")
  }
} else if (i %in% c("G", "F")){
  if (result %in% 0:10) {
    fin <- c("X", "W", "U", "T", "R", "Q", 

 - List item

"P", "N", "M", "L", "K")[result+1]
  }else {
    print("FIN is Invalid")
  }
} else {
  print("All is Invalid")
}}}

result$fin is still empty after that. I want to do a for loop such that each number in the result will correspond to each type of alphabet for example 1 = A and 2 = B.

Aucun commentaire:

Enregistrer un commentaire