Chris Marshall
2001-Apr-25 17:22 UTC
[R] how to do java-like hashtables in R, R from a java programmer's p onit of view
I suppose I am looking for recommendations on the right book on R for me. This post drones on a bit about what sort of programming I do and is basically asking if there are any books on R written with me in mind. I also make a proposal regarding R documentation at the end. I started reading "Programming with Data," by Chambers, got really excited in chapter 1, then found that I had a hard time learning what I wanted to know from the rest of it. I have been reading "An Introduction to R," which is quite good, but stops short of what I want to know. My company operates a satellite mobile data network and I am the "chief traffic analysist," you might say. I have a packet sniffer that captures a complete record of every packet that goes over the air in our network and from that, I study the system's capacity, do troubleshooting, and all sorts of other analysis. I plot things like channel utilisation versus time during the day, arrival and departure rates of calls in the system, arrival rates of different categories of packets, and many other things. I am no statistician (I'm a communictions theory guy who enjoys programming). I have written a lot of software to analyze the raw data in java and I am very attracted to R's interactive ploting and data analysis abilities. I am having a hard time making the connection between how I usually do things in java and how to do things in R, however. After I got the basic syntax of R down, one of the first questions I asked myself was."O.K., now how do I build a hashtable from a text file?" I took me a while to realize that R's lists are one way to do that. For example, suppose I have a text file with the following key/value pairs in it a,1 b,1 c,4 d,3 ... and I want to read this into a hash table. I must have written a dozen programs that do any number of variations on this basic task in the last year or so. I can't believe how useful it is. In R, you might proceed as follows to build such a table. Say x is some list object. Say you have a loop that is reading key/value pairs into the variables "key" and "value" one after another. Putting the pair in the table is as simple as: x[[key]] <- value Later, retrieving a value from a key would be: x[[key]] Are there any books that explain how to use the base packages in R or S to do tasks like this? I feel like I am really stumbling around in the dark trying to slowly figure things out in R. When writing a java program to perform some new type of analysis, I typically lay out a few obvious classes based on the sorts of data I am trying to extract and start filling in the details of the classes. Is this the right way to think of programming in R/S? It occurs to me that some simple java programs and their corresponding R implementations would be a very powerful form of documentation for java programmers wanting to learn R. This is my second attempt to come to grips with R; I tried and failed about a year ago. Perhaps this forum would be an excellent place to develop such example program translations? I would certainly be willing to boil down some of my typical java data analysis programs into short, clear examples, if anyone would be interested in helping me translate them into R. Chris Marshall -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
2001-Apr-25 20:06 UTC
[R] how to do java-like hashtables in R, R from a java programmer's p onit of view
Chris Marshall <chrism at norcomnetworks.com> writes:> In R, you might proceed as follows to build such a table. Say x is some > list object. Say you have a loop that is reading key/value pairs into the > variables "key" and "value" one after another. > > Putting the pair in the table is as simple as: > > x[[key]] <- value > > Later, retrieving a value from a key would be: > > x[[key]]Actually, the linear structure of a list in R makes this rather inefficient. Another option is to use environments and pretend that the key is a variable name: e <- new.env() assign(key,value,envir=e) get(key,envir=e) This has the advantage that environments, contrary to lists, really are hashed. Take a peek inside envir.c if you care. (Abandon all hopes of S-PLUS compatibility if you do this, though. Also beware that environments are slightly strange objects since they are never duplicated - e.g. on assignment.) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
M. Edward (Ed) Borasky
2001-Apr-25 20:44 UTC
[R] how to do java-like hashtables in R, R from a java programmer's p onit of view
On Wed, 25 Apr 2001, Chris Marshall wrote: [snip] I do some *very* similar things, except that I do the data structuring in Perl and create comma-separated value files that I can read directly into R with "read.csv". The basic data structure in R is the data frame, and most of my Perl code simply builds data frames. I have actually processed sniffer-like data. In the specific case, I simply built a list indexed by time stamp in milliseconds (column 1). Column 2 is the "from" IP address, column 2 is to "to" IP address, column 3 is the byte count and column 4 is the protocol. In actuality, my data came from Microsoft SMS NetMon rather than from a sniffer. Then all I have to do is read the data into a statistics package (when I did this I used Minitab, not R) and I can easily do analysis on packets by source, destination, protocol, etc. Contact me off- list for more details. -- znmeb at aracnet.com (M. Edward Borasky) http://www.aracnet.com/~znmeb How to Stop A Folksinger Cold # 3 "If you miss the train I'm on..." Tough. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._