dataframe - R-Transposing a data frame -


i need transpose large data frame , used:

df.aree <- t(df.aree) df.aree <- as.data.frame(df.aree) 

this obtain:

df.aree[c(1:5),c(1:5)]                          10428        10760        12148        11865     name                m231t3       m961t5       m960t6      m231t19     gs04.a        5.847557e+03 0.000000e+00 3.165891e+04 2.119232e+04     gs16.a        5.248690e+04 4.047780e+03 3.763850e+04 1.187454e+04     gs20.a        5.370910e+03 9.518396e+03 3.552036e+04 1.497956e+04     gs40.a        3.640794e+03 1.084391e+04 4.651735e+04 4.120606e+04     

my problem new column names(10428, 10760, 12148, 11865) need eliminate because need use first row column names.

i tried col.names() function haven't obtain need.

do have suggestion?

edit

thanks suggestion!!! using obtain:

df.aree[c(1:5),c(1:5)]                         m231t3       m961t5       m960t6      m231t19     gs04.a        5.847557e+03 0.000000e+00 3.165891e+04 2.119232e+04     gs16.a        5.248690e+04 4.047780e+03 3.763850e+04 1.187454e+04     gs20.a        5.370910e+03 9.518396e+03 3.552036e+04 1.497956e+04     gs40.a        3.640794e+03 1.084391e+04 4.651735e+04 4.120606e+04     gs44.a        1.225938e+04 2.681887e+03 1.154924e+04 4.202394e+04 

now need transform row names(gs..) in factor column....

you'd better not transpose data.frame while name column in - numeric values turned strings!

here's solution keeps numbers numbers:

# first remember names n <- df.aree$name  # transpose first column (name) df.aree <- as.data.frame(t(df.aree[,-1])) colnames(df.aree) <- n df.aree$myfactor <- factor(row.names(df.aree))  str(df.aree) # check column types 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -