[R] dataframe row names from list

Jim Lemon jim at bitwrit.com.au
Mon Sep 6 23:05:05 CEST 2010


On 09/06/2010 09:41 PM, rajeshj at cse.iitm.ac.in wrote:
>
> Hi,
> I have a list which looks like this...
>> str(y)
> List of 10
>   $ : chr [1:4] "ABCD" "5" "0" "1"
>   $ : chr [1:4] "DEF" "15" "1" "16"
>   $ : chr [1:4] "AAA" "2" "17" "8"
>   $ : chr [1:4] "SSS" "15" "25" "1"
>   $ : chr [1:4] "III" "15" "26" "4"
>   $ : chr [1:4] "OPQ" "7" "30" "4"
>   $ : chr [1:4] "TYR" "14" "34" "8"
>   $ : chr [1:4] "IRTS" "15" "42" "1"
>   $ : chr [1:4] "LLL" "15" "43" "2"
>   $ : chr [1:4] "AQW" "3" "45" "4"
>
> I need to create a dataframe whose row names are chr[1] of each vector..ie ABCD,DEF,AAA ETC. how can I do this?

Hi rajesh,
Try this:

rownames(mydf)<-unlist(lapply(y,"[",1))

Jim



More information about the R-help mailing list