for loops

12 views
Skip to first unread message

Ayala Allon

unread,
May 29, 2013, 10:05:52 AM5/29/13
to israel-r-...@googlegroups.com

שלום,

אני מנסה לכתוב loop שיעשה את הדבר הבא:

יש לי מטריצה עם n טורים. אני רוצה לתת לכל טור במטריצה את השם הבא:

X1,X2,X3…..Xn.

מכיוון שכל פעם המטריצה תהיה עם מספר טורים שונה אני רוצה לתת את השמות באמצעות לופ (או בכל דרך אחרת שהיא גמישה מספיק כדי שאני אצטרך לתת כל פעם רק את מספר הטורים במטריצה).

התחלתי לכתוב את הלופ הבא:

i=1

colnames(x)= for (i in 1:dim(x)[2]) paste("x", i)

אבל השמות שזה נותן לי לטורים זה:

         [,1]      [,2]     [,3]     [,4]

מה אני מפספסת? איך אני מעלה את i כל פעם באחד? ואם אפשר לקבל קצת הסבר על איך כותבים לופ אני אשמח.

תודה רבה,

אילה

Tal Galili

unread,
May 29, 2013, 10:11:28 AM5/29/13
to israel-r-...@googlegroups.com
היי אילה, תנסי:

colnames(x) <- paste("x", 1:n, sep = "")




----------------Contact Details:-------------------------------------------------------
Contact me: Tal.G...@gmail.com
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English)
----------------------------------------------------------------------------------------------



2013/5/29 Ayala Allon <ayala...@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.
 
 

Ayala Allon

unread,
May 29, 2013, 10:14:37 AM5/29/13
to israel-r-...@googlegroups.com
תודה רבה טל. הרבה יותר פשוט ממה שאני ניסיתי
אילה
2013/5/29 Ayala Allon <ayala...@gmail.com>
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages