Bodnar Laszlo EB_HU
2011-Mar-11 15:47 UTC
[R] changing one character in the name of dataframes repeatedly
Dear R-community, I'd like to ask you a question concerning R again. I try to keep this simple because I am not willing to confuse you at all. I have a little data frame which I have created the following way: a <-c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6) b <-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30) df <-as.data.frame(cbind(a,b)) df Now in the next step I would have liked to create smaller dataframes where the data have been extracted (basically splitted) from the main 'df' dataframe according to the numbers in df$a. Something like this: a b 1 1 1 2 1 3 1 4 1 5 a b 2 6 2 7 2 8 2 9 2 10 a b 3 11 3 12 3 13 3 14 3 15 a b 4 16 4 17 4 18 4 19 4 20 etc. It is not quite difficult to do this part. But!! I also want that the name of each and every small dataframe should refer to the fact that according to which number in df$a have I selected the data in df$b. For example: df.1 meaning I have only chosen those numbers in df$b which have value "1" in df$a df.1 a b 1 1 1 2 1 3 1 4 1 5 df.2 meaning I have only chosen those numbers in df$b which have value "2" in df$a. df.2 a b 2 6 2 7 2 8 2 9 2 10 df.3 meaning I have only chosen those numbers in df$b which have value "3" in df$a. a b 3 11 3 12 3 13 3 14 3 15 etc... I know it would not be difficult to do this in this way: df.1 <-split(df,df$a)[[1]] df.2 <-split(df,df$a)[[2]] df.3 <-split(df,df$a)[[3]] df.4 <-split(df,df$a)[[4]] etc... But as a matter of fact, my real df dataframe consists of more than 4400 records so it is impossible to do this "manually" for a numerous times with the previously mentioned split function. I wanted to use loops and managing the problem in the following (wrong) way: for (i in 1:6) { df.i <-split(df,df$a)[[i]] } After I wanted to enter df.1, df.2, etc... R sent me the message: Error: object 'df.1' not found. However, it recognized df.i and listed following: a b 6 26 6 27 6 28 6 29 6 30 Can you help me with this matter? I wonder if there is a proper way to do this which I haven't figured out yet... Thank you very much and have a pleasant weekend, Laszlo Bodnar ____________________________________________________________________________________________________ Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása, másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ felhasználásából vagy annak megbízhatatlanságából eredő kárért. Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos munkamenetének biztosítása érdekében. This e-mail and any attached files are confidential and/...{{dropped:19}}
Bodnar Laszlo EB_HU
2011-Mar-11 15:49 UTC
[R] changing one character in the name of dataframes repeatedly
Dear R-community, I'd like to ask you a question concerning R again. I try to keep this simple because I am not willing to confuse you at all. I have a little data frame which I have created the following way: a <-c(1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4,5,5,5,5,5,6,6,6,6,6) b <-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30) df <-as.data.frame(cbind(a,b)) df Now in the next step I would have liked to create smaller dataframes where the data have been extracted (basically splitted) from the main 'df' dataframe according to the numbers in df$a. Something like this: a b 1 1 1 2 1 3 1 4 1 5 a b 2 6 2 7 2 8 2 9 2 10 a b 3 11 3 12 3 13 3 14 3 15 a b 4 16 4 17 4 18 4 19 4 20 etc. It is not quite difficult to do this part. But!! I also want that the name of each and every small dataframe should refer to the fact that according to which number in df$a have I selected the data in df$b. For example: df.1 meaning I have only chosen those numbers in df$b which have value "1" in df$a df.1 a b 1 1 1 2 1 3 1 4 1 5 df.2 meaning I have only chosen those numbers in df$b which have value "2" in df$a. df.2 a b 2 6 2 7 2 8 2 9 2 10 df.3 meaning I have only chosen those numbers in df$b which have value "3" in df$a. a b 3 11 3 12 3 13 3 14 3 15 etc... I know it would not be difficult to do this in this way: df.1 <-split(df,df$a)[[1]] df.2 <-split(df,df$a)[[2]] df.3 <-split(df,df$a)[[3]] df.4 <-split(df,df$a)[[4]] etc... But as a matter of fact, my real df dataframe consists of more than 4400 records so it is impossible to do this "manually" for a numerous times with the previously mentioned split function. I wanted to use loops and managing the problem in the following (wrong) way: for (i in 1:6) { df.i <-split(df,df$a)[[i]] } After I wanted to enter df.1, df.2, etc... R sent me the message: Error: object 'df.1' not found. However, it recognized df.i and listed following: a b 6 26 6 27 6 28 6 29 6 30 Can you help me with this matter? I wonder if there is a proper way to do this which I haven't figured out yet... Thank you very much and have a pleasant weekend, Laszlo Bodnar ____________________________________________________________________________________________________ Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása, másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ felhasználásából vagy annak megbízhatatlanságából eredő kárért. Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul, hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos munkamenetének biztosítása érdekében. This e-mail and any attached files are confidential and/...{{dropped:19}}
Apparently Analagous Threads
- help - "the condition has length > 1 and only the first element will be used"
- bootstrap resampling - simplified
- changing the dimensions of a matrix in a real specific way
- creating additional column
- recalling different data frames (the way you do in Excel VB)