How to change column names in data frame in R?  names(mydat)[c(name)]<-c("newname") 

From this, I know that the column/variable name "name" of the data frame mydat is replaced with "newname".
My question is if, I want to do this by a loop so that I will have some thing like:
newname1 newname2 newname3 newname4 and so on, how do I do it?
This is what did and it did not work:
for(i in 1:4){
names(mydat)[c(name)]<-c("newname"i)
}

Is there a way to code this?
many thanks to all who could be of help.
Owusu Isaac
 A: Try using sprintf or paste, like this:
names(mydat)<-sprintf("name%d",1:10)

Also, note that the names(mydat)[c(name)] is a more-less a nonsense; c(name) is equivalent to writing just name and means "get the value of variable called name'; bracket will at least extract elements of names(mydat) but only if name variable holds a numeric or boolean index.
If you want to replace columns called name with name1, name2, ..., nameN, use something like this:
names(mydat)[names(mydat)=="name"]<-sprintf("name%d",1:sum(names(mydat)=="name"))

EDIT: Well, if you just want to remove duplicated column names, there is even easier way; R has a make.names function which fixes this problem; it can be used like this:
names(mydat)<-make.names(names(mydat),unique=TRUE)

Even shorter, the same can be obtained only by writing:
data.frame(mydat)->mydat #The magic is in check.names, but it is TRUE by default

A: I had the same problem and I solved it with this code:
names(mydat) <- paste("newname", 1:ncol(mydat), sep="");

A: Most obvious solution would be to change your code in for loop with the following:
   names(mydat)[c(name)] <- paste("newname",i,sep="")

But you need to clarify what your variable name is. At the moment this loop will do 4 renames of the single column.
In general if the names which you want to change are in vector, this is a standard subsetting procedure:
 names(mydat)[names(mydat)%in% names_to_be_changed] <- name_changes

