How do I search for a string in a data.frame? As a minimal example, how do I find the locations (columns and rows) of \'horse\' in this data.frame?
Another way around:
l <- sapply(colnames(df), function(x) grep("horse", df[,x])) $animal [1] 2 3 $level [1] 5 $length [1] 4
If you want the output to be matrix:
sapply(l,'[',1:max(lengths(l))) animal level length [1,] 2 5 4 [2,] 3 NA NA