wei x1
2010-May-03 18:21 UTC
[R] how to name the column after converting a vector to a data frame
hell all: I have a vector as follows:> head(res)1007_s_at.value 1053_at.value 117_at.value 121_at.value 1255_g_at.value 0.225801033 0.009747404 0.709517954 0.008825740 0.496859178 1294_at.value 0.005091231 after I convert the res into a data frame I got the following: resx<- data.frame(res)> head(resx)res 1007_s_at.value 0.225801033 1053_at.value 0.009747404 117_at.value 0.709517954 121_at.value 0.008825740 1255_g_at.value 0.496859178 1294_at.value 0.005091231 as you may see, the first column of resx has no names and it does not appear as one of dimension of data frame. I wonder anyone may have solution to assign a name to it. thanks _________________________________________________________________ The New Busy is not the too busy. Combine all your e-mail accounts with Hotmail. ID28326::T:WLMTAGL:ON:WL:en-US:WM_HMP:042010_4 [[alternative HTML version deleted]]
Barry Rowlingson
2010-May-03 19:12 UTC
[R] how to name the column after converting a vector to a data frame
On Mon, May 3, 2010 at 7:21 PM, wei x1 <weix1_2007 at hotmail.com> wrote:> > hell all: > > I have a vector as follows: > >> head(res) > 1007_s_at.value ? 1053_at.value ? ?117_at.value ? ?121_at.value 1255_g_at.value > ? ?0.225801033 ? ? 0.009747404 ? ? 0.709517954 ? ? 0.008825740 ? ? 0.496859178 > ?1294_at.value > ? ?0.005091231 > > > > after I convert the res into a data frame I got the following: > > resx<- data.frame(res) >> head(resx) > ? ? ? ? ? ? ? ? ? ? ? ?res > 1007_s_at.value 0.225801033 > 1053_at.value ? 0.009747404 > 117_at.value ? ?0.709517954 > 121_at.value ? ?0.008825740 > 1255_g_at.value 0.496859178 > 1294_at.value ? 0.005091231 > > > > as you may see, the first column of resx has no names and it does not appear as one of dimension of data frame. > > I wonder anyone may have solution to assign a name to it. >The first column isnt a column! It's the row names. If you want to make a column from the row names, try:> res=c(a=1,b=2,c=3) > resx=data.frame(res) > resxres a 1 b 2 c 3> resx$names = rownames(resx) > resxres names a 1 a b 2 b c 3 c now it has row names as well as a column (called 'names') with them in. Barry