r - Delete a cell based on content of corresponding column -


two requests. tried research online on how delete cell based on index, found nothing. appreciate if can direct me resources topic (this being solution problem below).

my problem deleting date cell based on corresponding trimmed.average column. if trimmed.average column empty "" or "trimmed average", date right should deleted.

i found answers remove entire row, want keep variable in row.

structure(list(variable = c("x", "x", "x", "x", "x", "x", "x",  "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x",  "x", "x", "x", "x", "x", "x", "x", "x", "x"), x1st = c("", "3.44",  "0.53", "1.66", "0.10", "0.91", "-0.25", "0.16", "-0.11", "0.16",  "0.09", "-0.19", "0.00", "0.09", "0.09", "", "81.00", "52.75",  "3.66", "0.58", "1st", "0.42", "0.05", "0.29", "0.91", "-2.12",  "", "23.14", "32.78"), x5th = c("", "4.48", "0.81", "2.85", "0.24",  "1.63", "0.00", "0.71", "-0.02", "0.74", "0.49", "0.51", "0.00",  "0.48", "0.49", "", "88.58", "63.76", "4.87", "0.89", "5th",  "0.81", "0.17", "0.43", "1.63", "0.88", "", "37.70", "38.55"),  x10th = c("", "4.73", "0.99", "3.10", "0.34", "1.93", "0.00",  "0.98", "0.00", "1.00", "0.67", "0.70", "0.00", "0.66", "0.67",  "", "90.05", "67.76", "5.11", "1.07", "10th", "0.98", "0.21",  "0.51", "1.93", "1.21", "", "44.33", "40.93"), x20th = c("",  "4.99", "1.21", "3.38", "0.50", "2.21", "0.03", "1.25", "0.00",  "1.28", "0.84", "0.89", "0.00", "0.82", "0.84", "", "91.53",  "72.93", "5.36", "1.30", "20th", "1.17", "0.27", "0.64",  "2.21", "1.53", "", "49.94", "44.32"), x25th = c("", "5.09",  "1.30", "3.46", "0.56", "2.33", "0.05", "1.34", "0.00", "1.35",  "0.91", "0.95", "0.00", "0.88", "0.91", "", "91.95", "74.57",  "5.44", "1.39", "25th", "1.25", "0.29", "0.67", "2.33", "1.61",  "", "52.74", "45.64"), x50th = c("", "5.42", "1.59", "3.84",  "0.81", "2.81", "0.13", "1.74", "0.00", "1.75", "1.17", "1.28",  "0.00", "1.13", "1.17", "", "93.79", "79.50", "5.78", "1.71",  "50th", "1.53", "0.40", "0.84", "2.81", "1.91", "", "59.58",  "52.20"), x75th = c("", "5.77", "1.86", "4.28", "1.15", "3.36",  "0.24", "2.15", "0.00", "2.18", "1.50", "1.62", "0.00", "1.40",  "1.50", "", "95.44", "83.61", "6.17", "1.98", "75th", "1.87",  "0.50", "1.05", "3.36", "2.28", "", "66.90", "62.47"), x80th = c("",  "5.91", "1.93", "4.41", "1.24", "3.51", "0.27", "2.31", "0.00",  "2.32", "1.62", "1.73", "0.00", "1.48", "1.62", "", "95.79",  "84.68", "6.33", "2.06", "80th", "1.97", "0.53", "1.11",  "3.51", "2.40", "", "69.24", "64.82"), x90th = c("", "6.22",  "2.12", "4.74", "1.64", "3.98", "0.37", "2.66", "0.03", "2.71",  "2.00", "2.11", "0.00", "1.73", "2.00", "", "96.77", "86.91",  "6.69", "2.24", "90th", "2.21", "0.63", "1.35", "3.98", "2.69",  "", "74.61", "76.34"), x95th = c("", "6.68", "2.25", "5.06",  "2.30", "4.66", "0.49", "3.16", "0.08", "3.20", "2.36", "2.45",  "0.00", "2.01", "2.36", "", "97.61", "88.15", "7.09", "2.38",  "95th", "2.62", "0.72", "1.59", "4.66", "2.93", "", "79.82",  "88.33"), x99th = c("", "8.57", "2.59", "6.76", "13.08",  "12.74", "1.68", "5.81", "0.28", "6.74", "4.65", "5.14",  "0.00", "4.13", "4.65", "", "99.18", "91.06", "9.23", "2.72",  "99th", "4.35", "1.03", "5.48", "12.74", "3.68", "", "93.81",  "149.14"), trimmed.average = c("", "5.45", "1.58", "3.88",  "0.88", "2.86", "0.15", "1.77", "0.00", "1.79", "1.22", "1.31",  "0.00", "1.15", "1.22", "", "93.64", "78.75", "5.83", "1.69",  "trimmed average", "1.57", "0.40", "0.87", "2.86", "1.93",  "", "59.66", "54.70"), date = c("2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31", "2005-03-31",  "2005-03-31", "2005-03-31")), .names = c("variable", "x1st",  "x5th", "x10th", "x20th", "x25th", "x50th", "x75th", "x80th",  "x90th", "x95th", "x99th", "trimmed.average", "date"), row.names = c(1l,  2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 10l, 11l, 12l, 13l, 14l, 15l,  16l, 17l, 18l, 19l, 20l, 52l, 53l, 54l, 55l, 56l, 57l, 58l, 59l,  60l), class = "data.frame")         

we use %in% index of elements either '' or trimmed average in column 'trimmed.average' , use assign 'date' column values ''.

df1$date[df1$trimmed.average%in% c('', 'trimmed average')] <- '' 

or can done data.table

library(data.table)#v1.9.5+ setdt(df1)[trimmed.average %chin% c('', 'trimmed average'), date:=''] 

Comments