How to use for loop to assign similar sample names to a number using a for loop

15 Views Asked by At

I have a data set (moist) that has a column with my sample ID names with four different groups. I want to assign the sample ID names in each group with a number (1-4). So I am trying to write if the sample name starts with "TE-WM" or "TC-WM", then output = 1, "AE-MM" and "AC-MM" = 2, "LE-DM" and "LC-DM" = 3, and "EE-DM" and "EC-DM" = 4. Below is the code I am trying to use and I am getting an error that says "character string is not in a standard unambiguous format".

output <- c(moist$`Sample ID`)
  ifelse(output == moist[grep("TE-WM",output),], output == 1, output)

I want the output to be a column that has the numbers for each sample ID in each row

0

There are 0 best solutions below