Here you will find daily news and tutorials about R, contributed by over 750 bloggers.
There are many ways to follow us - By e-mail:On Facebook: If you are an R blogger yourself you are invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here)

There’s an old saying that goes: “If you dream and want something hard enough, but have no commitment….then you’re probably full of shit”. After having finished the Getting and Cleaning Data course on Coursera, I haven’t typed a single line of R code in a long time; and since i was only just starting out on the basics, my foundations in the language are a little shaky again. So i had to start all over again.

Below is a function that loops through an entire dataframe and find all the column names that contain a given value.

searchCol = function(name, dataframe){
x = 0
newList = c() #This will be vector that would be returned
#Start loop for all the values to be seached for
for(i in 1:length(name)){
#Start loop for each row in the dataframe...
for(j in 1:nrow(dataframe)){
#...same thing for the columns
for(k in 1:ncol(dataframe)){
#If the matching criteria is met, add the value to the newList vector
if(dataframe[j,k] == name[i]){
newList[x+1] = names(dataframe)[k]
x = x+1
}
}
}
}
return(newList)
}