1
I have a DF and would like to consult multiple columns at the same time in an Auxiliary Table. Example of DF:
MATRICULA <- c(123,456,789,111,222,333)
DIA_1 <- c('ARROZ','','ARROZ','','ARROZ','')
DIA_2 <- c('FEIJAO','','FEIJAO','','','FEIJAO')
DIA_3 <- c('BATATA','','BATATA','','BATATA','BATATA')
DIA_4 <- c('COUVE','COUVE','','COUVE','','COUVE')
DIA_5 <- c('BIFE','','BIFE','','BIFE','BIFE')
DADOS <- data.frame(MATRICULA,DIA_1,DIA_2,DIA_3,DIA_4,DIA_5)
My Auxiliary Table
AUXILIAR <- c('ARRROZ','FEIJAO')
TABELA_AUX <- data.frame(AUXILIAR)
Therefore, I would like to consult the 5 columns at the same time (DIA_1 to DIA_5) to check if the plate consumed any food from the Auxiliary Table (rice OR ugliness).
As a result, I would like to see the following output:
MATRICULA <- c(123,456,789,111,222,333)
DIA_1 <- c('ARROZ','','ARROZ','','ARROZ','')
DIA_2 <- c('FEIJAO','','FEIJAO','','','FEIJAO')
DIA_3 <- c('BATATA','','BATATA','','BATATA','BATATA')
DIA_4 <- c('COUVE','COUVE','','COUVE','','COUVE')
DIA_5 <- c('BIFE','','BIFE','','BIFE','BIFE')
VERIFICACAO <- c('SIM','NAO','SIM','NAO','SIM','SIM')
RESULTADO <- data.frame(MATRICULA,DIA_1,DIA_2,DIA_3,DIA_4,DIA_5,VERIFICACAO)
Thank you!
Dear Jorge, thank you! However, the way you put the "CHECK" column indicates that it was not built automatically (you already report the results). My problem would be how to automatically build the "CHECK" column. Also, I realized that your query sweeps all rows of the file, however I can’t do that, I have to limit only to these columns (DIA_1 until DIA_5). Could you help me again after these remarks? Thank you.
– Bruno Avila
I edit with some modifications. Only I created the column automatically, using DATA and HELPER. At the end I only created a column with the name "CHECK" because it is a better name than "VERIFICACAO_1", but I did not use the example variable. I left it there just for testing.
– Jorge Mendes
I made the edits. I put a filter vector for the columns and left the test pro final, to make it clearer than the vector
VERIFICACAO
did not enter the table.– Jorge Mendes
Thanks again. You said you have other ways besides this with apply. Could you show me another suggestion if possible? Thanks.
– Bruno Avila
Okay, I did one more issue
– Jorge Mendes