Bodnar Laszlo EB_HU
2011-Mar-21 16:14 UTC
[R] recalling different data frames (the way you do in Excel VB)
Hello everyone,
I'd like to ask you a question again, basically focusing on referring to
different objects.
Let's suppose we create the following databases this way:
id <-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
a <-c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
b <-c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
c <-c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
d <-c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
e <-c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,4)
df <-data.frame(id,a,b,c,d,e)
df
for (i in 1:3) assign(paste("df", i, sep="."),
split(df,df$id)[[i]])
df.1
df.2
df.3
Now in the next step I'd like to get or "recall" these databases
but not just simply sending 'df.1', 'df.2', 'df.3' to R
(because my real df database is much bigger and much more complicated than this
simplified one as usual). I would have liked to do this the similar way you
recall these things in Excel Visual Basic.
You know, if we were in an Excel VB world I would do something like:
sub exercise ()
for i = 1 to 3
df.i
// perform this and that etc.//
next i
end sub
Returning to R: first I wanted to do it this way:
for (i in 1:3)
df.i (perform this and that etc...)
But of course it is wrong. Is there a proper way to handle this one? What do I
miss? I do not know if my question is clear...
Thank you very much and thanks for the previous answers as well!
Happy R-exploring!
Laszlo
____________________________________________________________________________________________________
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}}
Eik Vettorazzi
2011-Mar-22 11:00 UTC
[R] recalling different data frames (the way you do in Excel VB)
Hi Laszlo,
the "see also" part of ?assign comes in use here, it leads to
"get"
get(paste("df",i,sep=".")
Cheers
Am 21.03.2011 17:14, schrieb Bodnar Laszlo EB_HU:> Hello everyone,
>
>
>
> I'd like to ask you a question again, basically focusing on referring
to different objects.
>
>
>
> Let's suppose we create the following databases this way:
>
>
>
> id <-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
>
> a <-c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
>
> b <-c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
>
> c <-c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
>
> d <-c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
>
> e <-c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,4)
>
> df <-data.frame(id,a,b,c,d,e)
>
> df
>
>
>
> for (i in 1:3) assign(paste("df", i, sep="."),
split(df,df$id)[[i]])
>
> df.1
>
> df.2
>
> df.3
>
>
>
> Now in the next step I'd like to get or "recall" these
databases but not just simply sending 'df.1', 'df.2',
'df.3' to R (because my real df database is much bigger and much more
complicated than this simplified one as usual). I would have liked to do this
the similar way you recall these things in Excel Visual Basic.
>
>
>
> You know, if we were in an Excel VB world I would do something like:
>
> sub exercise ()
>
> for i = 1 to 3
>
> df.i
>
> // perform this and that etc.//
>
> next i
>
> end sub
>
>
>
> Returning to R: first I wanted to do it this way:
>
> for (i in 1:3)
>
> df.i (perform this and that etc...)
>
>
>
> But of course it is wrong. Is there a proper way to handle this one? What
do I miss? I do not know if my question is clear...
>
> Thank you very much and thanks for the previous answers as well!
>
> Happy R-exploring!
>
> Laszlo
>
>
>
>
____________________________________________________________________________________________________
>
> 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}}
>
>
>
>
> ______________________________________________
> 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.
--
Eik Vettorazzi
Institut f?r Medizinische Biometrie und Epidemiologie
Universit?tsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
Reasonably Related Threads
- recalling different data frames (the way you do in Excel VB but now) in
- persuade tabulate function to count NAs in a data frame
- calculating the occurrences of distinct observations in the subsets of a dataframe
- changing the dimensions of a matrix in a real specific way
- creating additional column