r - Change names of only some columns -


i have set of data looks following:

v1,v2,v3,v4,lm,q1.1,q1.2 "id","set","name","status","lm","first question","second question" "rx0102","default","respondentname1",0,,1,1 "rt1832","default","respondentname2",0,,1,1 

i want take of columns names start v , rename them using value first row. know how names (colnames(f[,c(grep("^v[0-9]*$",names(f)))]) return "v1", "v2", "v3", "v4") , positions (grep("^v[0-9]*$",names(f)) return 1, 2, 3, 4) of columns, , know how respective values first row (f[1,c(grep("^v[0-9]*$", names(f)))]). can't seem assign first row values names. have tried this:

colnames(f[,c(grep("^v[0-9]*$",names(f)))]) <- f[1,c(grep("^v[0-9]*$", names(f)))] 

but nothing. can please tell me doing wrong?

you way:

colnames(f)[grep("^v[0-9]*$",names(f))] <- f[1,c(grep("^v[0-9]*$", names(f)))] 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -