Mohammad Tanvir Ahamed
2014-Jan-03 09:04 UTC
[R] Select rows of a data frame according to values of vector in a list
Hi there !! I have a list like as follows :>lis$lis1 [1] 1 3 5 $lis2 [1] 2 4 6 8 9 I have another data frame like as follows>df1 10 110 2 15 120 3 20 130 4 25 140 5 30 150 6 35 160 7 40 150 8 45 180 9 50 190 Now i want to select the rows of data frame by the value of list and the output will be as list and as follows>dat$lis1 1 10 110 3 20 130 5 30 150 $lis2 2 15 120 4 25 140 6 35 160 8 45 180 9 50 190 Any help will be very much appreciated. !! Best regards ........................... Tanvir Ahamed Göteborg, Sweden [[alternative HTML version deleted]]
Rui Barradas
2014-Jan-03 09:58 UTC
[R] Select rows of a data frame according to values of vector in a list
Hello, Try the following. lapply(lis, function(i) df[i, ]) Hope this helps, Rui Barradas Em 03-01-2014 09:04, Mohammad Tanvir Ahamed escreveu:> Hi there !! > > I have a list like as follows : >> lis > $lis1 > [1] 1 3 5 > > $lis2 > [1] 2 4 6 8 9 > > I have another data frame like as follows >> df > 1 10 110 > 2 15 120 > 3 20 130 > 4 25 140 > 5 30 150 > 6 35 160 > 7 40 150 > 8 45 180 > 9 50 190 > > Now i want to select the rows of data frame by the value of list and the output will be as list and as follows > >> dat > $lis1 > 1 10 110 > 3 20 130 > 5 30 150 > > $lis2 > 2 15 120 > 4 25 140 > 6 35 160 > 8 45 180 > 9 50 190 > > Any help will be very much appreciated. !! > > > Best regards > > > ........................... > Tanvir Ahamed > G?teborg, Sweden > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >