R-how to add columns to a data frame in a for loop? -



R-how to add columns to a data frame in a for loop? -

i have info looks , 1000 files same info format.

r_338 4 r_341 1 r_471 1 r_491 4 r_494 1 r_642 0 m_218 5 m_222 5 m_292 0 p_185 5 p_187 5 a_308 0 a_473 1

i appreciate if can direct me how can write r script can merge 1000 files keeping first column 1 time , rest 0f 1000 columns appended:

example output:

r_338 4 5 6 7 8 9 10 11 r_341 1 1 1 1 1 1 1 1 r_471 1 1 0 1 1 1 2 1 r_491 4 4 4 4 4 4 2 0 r_494 1 1 1 1 1 1 1 1 r_642 0 1 0 9 1 1 2 1 m_218 5 5 5 9 5 5 5 9 m_222 5 5 5 5 5 5 5 5 m_292 0 5 1 1 1 1 1 1 p_185 5 5 5 6 5 5 5 5 p_187 5 9 5 5 5 5 3 5 a_308 0 4 4 4 2 4 4 4 a_473 1 1 1 1 0 1 1 0

suppose have character vector containing file names. think

l <- lapply(file.names,read.table,...) ## ... represents additional ## arguments read.table() cbind(l[[1]],do.call(cbind,lapply(l[-1],"[[",2)))

might work.

r for-loop

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -