Question: how to give column names for a data in R
0
gravatar for mms140130
5 weeks ago by
mms14013030
mms14013030 wrote:

hello,

I have a file with 1117 columns and I have the names of these columns but how to give the names to those columns

it is not efficient to write

colnames(data)=c("name1", "name2",.....) because they are 1117 names

any help

R • 141 views
ADD COMMENTlink modified 5 weeks ago by theobroma22380 • written 5 weeks ago by mms14013030

@Charles Plessy could you please write your comment here

ADD REPLYlink written 5 weeks ago by mms14013030

I do not know what is going wrong with Biostars, I wrote my comment and then it gave me:

404 Error
Page at /p/236697/ not found!

Anyway, it is now covered by the other comments (read from a file or use paste)

ADD REPLYlink written 5 weeks ago by Charles Plessy1.5k

where are the column names? in another file?

ADD REPLYlink written 5 weeks ago by shenwei3562.3k

yes the are in another file

ADD REPLYlink written 5 weeks ago by mms14013030
1
nms <- readLines("your_file_that_stores_colname_one_at_each_line")
colnames(data) <- nms
ADD REPLYlink written 5 weeks ago by Guangchuang Yu1.4k

Thank you very much :)

ADD REPLYlink written 5 weeks ago by mms14013030

What R commands are you using to read your data?

ADD REPLYlink written 5 weeks ago by ddiez1.5k
0
gravatar for theobroma22
5 weeks ago by
theobroma22380
theobroma22380 wrote:

N = 1117; nms = paste0("Name", 1:N); colnames(data) = nms; rm(N, nms)

ADD COMMENTlink written 5 weeks ago by theobroma22380
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1000 users visited in the last hour