רשימה של רשימות של וקטורים

12 views
Skip to first unread message

amit gal

unread,
Jun 6, 2013, 5:12:34 AM6/6/13
to israel-r-...@googlegroups.com
יש לי רשימה המכילה K רשימות, בכל רשימה פנימית כזו יש M וקטורים שכולם באורך N.

אני רוצה לצרף (באמצעות cbind) את כל הוקטורים שנמצאים באותו מקום ברשימות הפנימיות, ולקבל בעקבות זאת רשימה באורך M של מטריצות בגודל N*K

אני מחפש איזשהו צירוף נחמד של פקודות apply למיניהן וdo.call שתעשה את העבודה.

המלצות יתקבלו בברכה. דוגמא לנתונים מפוברקים:

ol = list()
for (i in 1:3) ol[[i]] = list()

for (i in 1:3) {
for (j in 1:4) {
  ol[[i]][[j]] = sample(20,10)
}}

#now there should be some operation that receives ol as parameter
# and return a list with 4 elements, each element is a 10*3 matrix

בינתיים אני כותב לולאות וכו'... מחפש פתרון גיקי ואלגנטי.

עמית

Yizhar Toren

unread,
Jun 6, 2013, 5:18:45 AM6/6/13
to israel-r-user-group@googlegroups com
התשובה בגוף השאלה :)

lapply(ol, do.call, what = "rbind")

במקרה הזה השתמשתי ב lapply פשוט כדי שהפונקציה לא "תאנוס" את התוצאה להיות טבלה אחת אלא תשאיר list של טבלאות


2013/6/6 amit gal <amit...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

amit gal

unread,
Jun 6, 2013, 5:24:47 AM6/6/13
to israel-r-...@googlegroups.com
זה לא נותן בדיוק את מה שאני צריך (אני צריך רשימה באורך 4 בדוגמה, ושלושה טורים בכל מטריצה, בעוד הפקודה שלך נותנת רשימה באורך 3 ו4 טורים בכל מטריצה) - אבל זה נתן לי רעיון. הולך ובודק ומשפצר אותו ומדווח אם הצלחתי (או לא)


2013/6/6 Yizhar Toren <yto...@gmail.com>

amit gal

unread,
Jun 6, 2013, 5:28:14 AM6/6/13
to israel-r-...@googlegroups.com
רק הייתי צריך את האוורור הזה של הצורך כדי לקבל את ההשראה :-)

הנה הפתרון:
##
do.call(function(...) mapply(cbind,...,SIMPLIFY=FALSE),ol)
##



2013/6/6 amit gal <amit...@gmail.com>
Reply all
Reply to author
Forward
0 new messages