Re: [R] Seeking help with a loop

2005-08-03 Thread Tony Plate
in a data frame: # (use paste() or sub() to modify the names if you # want something like newfielda) for (i in names(y)) assign(i, y[[i]]) a [1] 3 NA b [1] NA 6 hope this helps, Tony Plate Greg Blevins wrote: Hello R Helpers, After spending considerable time attempting

Re: [R] Why only a string for heading for row.names with write.csv with a matrix?

2005-08-10 Thread Tony Plate
, especially in cases where there desired functionality can be easily achieved in other ways with existing functions. -- Tony Plate Earl F. Glynn wrote: Consider: x - matrix(1:6, 2,3) rownames(x) - c(ID1, ID2) colnames(x) - c(Attr1, Attr2, Attr3) x Attr1 Attr2 Attr3 ID1 1 3 5

Re: [R] queer data set

2005-08-15 Thread Tony Plate
or an actual character NA value in column 4. If you're processing a huge amount of data, you can probably do better by rewriting the above code to avoid implicit coercions of data types. hope this helps, Tony Plate S.O. Nyangoma wrote: I have a dataset that is basically structureless. Its

Re: [R] Regular expressions sub

2005-08-18 Thread Tony Plate
x - scan(clipboard, what=) Read 7 items x [1] 1.11 10.11 11.11 113.31 114.2 114.3 114.8 gsub([0-9]*\\., , x) [1] 11 11 11 31 2 3 8 Bernd Weiss wrote: Dear all, I am struggling with the use of regular expression. I got as.character(test$sample.id) [1] 1.11 10.11

Re: [R] books about MCMC to use MCMC R packages?

2005-09-23 Thread Tony Plate
I've found Bayesian Data Analysis by Gelman, Carlin, Stern Rubin (2nd ed) to be quite useful for understanding how MCMC can be used for Bayesian models. It has a little bit of R code in it too. -- Tony Plate Molins, Jordi wrote: Dear list users, I need to learn about MCMC methods

Re: [R] Assign references

2005-10-07 Thread Tony Plate
and/or others down the road (because R is just not intended to be used that way). The standard way of doing this sort of thing in R is to modify a local copy of the dataframe and return that, or if you have to return several dataframes, then return a list of dataframes. -- Tony Plate [EMAIL

Re: [R] R on a supercomputer

2005-10-10 Thread Tony Plate
of the computation done in your R program involves basic linear algebra (matrix multiplication, etc.), then you might see a good speedup. -- Tony Plate Kimpel, Mark William wrote: I am using R with Bioconductor to perform analyses on large datasets using bootstrap methods. In an attempt to speed

Re: [R] transformation matrice of vector into array

2006-07-27 Thread Tony Plate
() function can help.) -- Tony Plate Jessica Gervais wrote: Hi, I need some help I have a matrix M(m,n) in which each element is a vector V of lenght 6 1 2 3 4 5 6 7 1 List,6 List,6 List,6 List,6 List,6 List,6 List,6 2 List,6 List,6 List,6 List,6 List,6 List,6

Re: [R] Functions ,Optim, Dataframe

2006-07-31 Thread Tony Plate
a '...' argument. -- Tony Plate Michael Papenfus wrote: I think I need to clarify a little further on my original question. I have the following two rows of data: mydat-data.frame(d1=c(3,5),d2=c(6,10),p1=c(.55,.05),p2=c(.85,.35)) mydat d1 d2 p1 p2 1 3 6 0.55 0.85 2 5 10 0.05 0.35 I need

Re: [R] Functions ,Optim, Dataframe

2006-07-31 Thread Tony Plate
I added an example of passing additional arguments through optim() to the objective and gradient functions to the Discussion section of the Wiki-fied R documentation. See it at http://wiki.r-project.org/rwiki/doku.php?id=rdoc:stats:optim -- Tony Plate PS. I had to add purge=true to the end

Re: [R] deleting a directory

2006-08-01 Thread Tony Plate
?unlink says that unlink() can remove directories (and has a 'recursive' argument). 'unlink' is in the SEE ALSO section in ?file.remove. -- Tony Plate Sundar Dorai-Raj wrote: Hi, all, I'm looking a utility for removing a directory from within R. Currently, I'm using: foo - function

Re: [R] meta characters in file path

2006-08-03 Thread Tony Plate
What is the problem you are having? Seems to work fine for me running under Windows2000: write.table(data.frame(a=1:3,b=4:6), file=@# x.csv, sep=,) read.csv(file=@# x.csv) a b 1 1 4 2 2 5 3 3 6 sessionInfo() Version 2.3.1 (2006-06-01) i386-pc-mingw32 attached base packages: [1]

Re: [R] regex scares me

2006-08-28 Thread Tony Plate
I think this does the trick. Note that it is case sensitive. x - c(lad.tab, xxladyy.tab, xxyy.tab, lad.tabx, LAD.tab, lad.TAB) grep(lad.*\\.tab$, x, value=T) [1] lad.tab xxladyy.tab Jon Minton wrote: Hi, apologies if this is too simple but I've been stuck on the following for a

Re: [R] Cannot get simple data.frame binding.

2006-08-28 Thread Tony Plate
data frame is causing the problem? Did you try as.data.frame(md1[,1:11])? (I'm guessing that will strip off extra attributes). -- Tony Plate John Kane wrote: I am stuck on a simple problem where an example works fine but the real one does not. I have a data.frame where I wish to sum up some

Re: [R] problem with putting objects in list

2006-09-06 Thread Tony Plate
I suspect you are not thinking about the list and the subsetting/extraction operators in the right way. A list contains a number of components. To get a subset of the list, use the '[' operator. The subset can contain zero or more components of the list, and it is a list itself. So, if x is

Re: [R] rename cols

2006-09-11 Thread Tony Plate
(Apple, Orange)' also works, because a dataframe is stored internally as a list of columns. -- Tony Plate Ethan Johnsons wrote: A quick question please! How do you rename column names? i.e. V1 -- Apple; V2 -- Orange, etc. thx much ej [[alternative HTML version deleted

Re: [R] Access Rows in a Data Frame by Row Name

2006-09-13 Thread Tony Plate
will probably be well worth it. The relevant sections are 5 Arrays and matrices, and 6.3 Data frames. -- Tony Plate Michael Gormley wrote: I have created a data frame using the read.table command. I want to be able to access the rows by the row name, or a vector of row names. I know that you can

Re: [R] symbolic matrix elements...

2006-09-18 Thread Tony Plate
is much safer if you just want to make lists of them. -- Tony Plate Evan Cooch wrote: Eik Vettorazzi wrote: test=matrix(c( expression(x^3-5*x+4), expression(log(x^2-4*x works. Well, not really (or I'm misunderstanding). Your code enters fine (no errors), but I can't access individual

Re: [R] List-manipulation

2006-09-29 Thread Tony Plate
Does this do what you want? x - list(1,2,3:7,8,9:10) sapply(x, function(xx) xx[1]) [1] 1 2 3 8 9 -- Tony Plate Benjamin Otto wrote: Hi, Sorry for the question, I know it should be basic knowledge but I'm struggling for two hours now. How do I select only the first entry

Re: [R] how ot replace the diagonal of a matrix

2006-10-03 Thread Tony Plate
will be more efficient, I believe.) -- Tony Plate roger bos wrote: Dear useRs, Trying to replace the diagonal of a matrix is not working for me. I want a matrix with .6 on the diag and .4 elsewhere. The following code looks like it should work--when I lookk at mps and idx they look how I want

Re: [R] shifting a huge matrix left or right efficiently ?

2006-10-09 Thread Tony Plate
0 400980 5000 12 10 I don't know if the conversion to and from a time-series class will impact the timing, but if this might serve your purposes, it's easy to do some experiments to find out. - Tony Plate Huang-Wen Chen wrote: I'm wondering what's

Re: [R] Fwd: rarefy a matrix of counts

2006-10-11 Thread Tony Plate
) -- Tony Plate From reading ?sample, I was a little unclear on whether sampling without replacement could work Petr Pikal wrote: Hi a litle bit different story. But x1 - sample(c(rep(red,400),rep(green, 100), rep(black,300)),100) is maybe close. With data frame (if it is not big) DF

Re: [R] Fwd: rarefy a matrix of counts

2006-10-11 Thread Tony Plate
red red red -- Tony Plate Brian Frappier wrote: I tried all of the approaches below. the problem with: x - data.frame(matrix(NA,100,3)) for (i in 2:ncol(DF)) x[,i-1] - sample(rep(DF[,1], DF[,i]),100) if you want result in data frame or x-vector(list, 3) for (i in 2

Re: [R] enter browser on error

2004-08-31 Thread Tony Plate
use options(error=recover), e.g.: remove(x) NULL Warning message: remove: variable x was not found (function() {x})() Error in (function() { : Object x not found options(error=recover) (function(y=1) {x})(2) Error in (function(y = 1) { : Object x not found Enter a frame number, or 0 to exit

Re: [R] Signs of loadings from princomp on Windows

2004-09-14 Thread Tony Plate
(unstable) major2 minor0.0 year 2004 month09 day 13 language R -- Tony Plate At Tuesday 10:25 AM 9/14/2004, Prof Brian Ripley wrote: On Tue, 14 Sep 2004, Francisco Chamu wrote: I have run this on both Windows 2000 and XP. All I did was install the binaries from CRAN so I

Re: [R] efficient submatrix extraction

2004-09-15 Thread Tony Plate
] [,4] [1,] 37 45 53 61 [2,] 38 46 54 62 [3,] 39 47 55 63 [4,] 40 48 56 64 hope this helps, Tony Plate At Wednesday 03:10 PM 9/15/2004, Rajarshi Guha wrote: Hi, I have a matrix of say 1024x1024 and I want to look at it in chunks. That is I'd like to divide

Re: [R] Signs of loadings from princomp on Windows

2004-09-15 Thread Tony Plate
that bothered you, but didn't bother dig deeper suggests it didn't bother them that much, which further suggests that you are the person most motivated by this and thus the best candidate for investigating it further...) -- Tony Plate At Wednesday 05:07 PM 9/15/2004, Francisco Chamu wrote: I am sorry

Re: [R] There were 50 or more warnings (use warnings() to see the first 50)

2004-09-16 Thread Tony Plate
Try putting options(warn=1) at the start of your R code. This should cause the warnings to be printed as they occur, instead of the default of being saved up until the top-level command terminates. See ?warning and ?option. -- Tony Plate At Thursday 08:52 AM 9/16/2004, Mag. Ferri Leberl wrote: I

Re: [R] read 4-jan-02 as date

2004-10-11 Thread Tony Plate
2001-01-11 2001-01-10 2001-01-09 2001-01-08 [6] 2001-01-05 as.Date(factor(d), format=%d-%b-%y) Error in fromchar(x) : character string is not in a standard unambiguous format Hope this helps, Tony Plate At Monday 09:04 AM 10/11/2004, bogdan romocea wrote: Dear R users, I have a column with dates

Re: [R] How might one write this better?

2004-10-05 Thread Tony Plate
The trick to vectorizing asset - numeric(T+1) for (t in 1:T) asset[t+1] - cont[t] + ret[t]*asset[t] is to expand it algebraically into a sum of terms like: asset[4] = cont[3] + ret[3] * cont[2] + ret[3] * ret[2] * cont[1] (where the general case should be reasonably obvious, but is more work to

Re: [R] Equivalents of Matlab's 'find' and 'end'

2004-10-07 Thread Tony Plate
At Thursday 08:10 AM 10/7/2004, Bryan L. Brown wrote: Sorry if these questions have been asked recently--I'm new to this list. I'm primarily a Matlab user who is attempting to learn R and I'm searching for possible equivalents of commands that I found very handy in Matlab. So that I don't seem

Re: [R] R-(wiki)-pedia?

2004-10-07 Thread Tony Plate
as a framework to get things going? If the existing R-docs are dumped into a wiki, won't the copy in the Wiki quickly get out of date? How does one get around this problem? -- Tony Plate __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman

Re: [R] gsub() on Matrix

2004-10-28 Thread Tony Plate
=T) [1] i1 + x2 + x10 + xx1 gsub(\\bx1\\b, i1, x1 + x2 + x10 + xx1, perl=F) [1] i1 + x2 + x10 + xx1 gsub(\\bx1\\b, i1, x1 + x2 + x10 + xx1, perl=F, ext=F) [1] i1 + x2 + x10 + xx1 (I assumed the fact that you have a matrix of strings is not relevant.) Hope this helps, Tony Plate At Wednesday 09:07

Re: [R] why should you set the mode in a vector?

2004-10-29 Thread Tony Plate
in as.double.default(list(as.integer(c(1, 2, 3)), foo, 3, 4)) : (list) object cannot be coerced to double x - v[2:4] mode(x) - numeric x [1] NA NA NA -- Tony Plate At Friday 03:41 PM 10/29/2004, Joel Bremson wrote: Hi all, If I write v = vector(mode=numeric,length=10) I'm still allowed to assign

Re: [R] make apply() return a list

2004-11-01 Thread Tony Plate
for()-loops aren't so bad. Look inside the code of apply() and see what it uses! The important thing is that you use vectorized functions to manipulate vectors. It's often fine to use for-loops to manipulate the rows or columns of a matrix, but once you've extracted a row or a column, then

Re: [R] Reading word by word in a dataset

2004-11-01 Thread Tony Plate
$Japan do: scan(clipboard, , flush=T) Read 3 items [1] i1-apple i2-banana i3-strawberry sub(^[A-Za-z0-9]*-, , scan(clipboard, , flush=T)) Read 3 items [1] apple banana strawberry -- Tony Plate At Monday 01:59 PM 11/1/2004, Spencer Graves wrote: Uwe and Andy's solutions

Re: [R] Resources for optimizing code

2004-11-05 Thread Tony Plate
Have you tried reading the manual An Introduction to R, with special attention to Array Indexing (indexing for data frames is pretty similar to indexing for matrices). Unless I'm misunderstanding, what you want to do is very simple. It is possible to use numeric vectors with 0 and 1 to

Re: [R] hashing using named lists

2004-11-18 Thread Tony Plate
() -- it does seem to require exact matches on names, e.g.: all.equal(list(a=1:3), list(aa=1:3)) [1] Names: 1 string mismatches all.equal(list(aa=1:3), list(a=1:3)) [1] Names: 1 string mismatches (the above run in R 2.0.0) -- Tony Plate (BTW, in R this operation is generally called indexing

Re: [R] Re: Protocol for answering basic questions

2004-12-04 Thread Tony Plate
as appropriate. -- Tony Plate __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

RE: [R] Percentages in contingency tables *warning trivial question*

2004-12-13 Thread Tony Plate
The 'abind' function in the 'abind' package is a generalized binding functions for arrays. (I've never tried it with tables.) At Monday 04:36 AM 12/13/2004, BXC (Bendix Carstensen) wrote: [...snip...] The last step is necessary in the absence of a generalized cbind/rbind for tables/arrays.

Re: [R] reading the seed from a simulation

2004-12-17 Thread Tony Plate
, 5) [1] 90 94 65 62 6 This is not guaranteed to work with all random-number generators; see the NOTE section in ?set.seed -- Tony Plate At Friday 09:50 AM 12/17/2004, Suzette Blanchard wrote: Greetings, I have a simulation of a nonlinear model that is failing. But it does not fail til

Re: [R] two dimensional array of object elements

2005-02-11 Thread Tony Plate
Create your original matrix as a list datatype. When assigning elements, be careful with the list structure, as the example indicates. m - 2; n - 3 a - array(list(),c(m,n)) a[1,2] - list(b=1,c=2) Error in [-(`*tmp*`, 1, 2, value = list(b = 1, c = 2)) : number of items to replace is

Re: [R] problem using uniroot with integrate

2005-03-09 Thread Tony Plate
, it would be best to remove the incorrect recursive default arguments for the functions est.dp and pr. -- Tony Plate __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org

Re: [R] how to multiply a constant to a matrix?

2006-05-26 Thread Tony Plate
be handled in an analogous manner, by always wrapping appropriate quadratic expressions in drop(), or are there some cases where the result of the quadratic expression must be treated as a matrix, and other cases where the result of the quadratic expression must be treated as a scalar? -- Tony Plate

Re: [R] max / pmax

2006-05-30 Thread Tony Plate
Here's an example of how I think you can do what you want. Play with the definition of the function highest.use() to get random selection of multiple maxima. drug.names - c(marijuana, crack, cocaine, heroin) drugs - factor(drug.names, levels=drug.names) drugs [1] marijuana crack

Re: [R] References verifying accuracy of R for basic statistical calculations and tests

2006-07-13 Thread Tony Plate
[leaving the and of in the query results in the search engine timing out - odd?] -- Tony Plate Corey Powell wrote: Do you know of any references that verify the accuracy of R for basic statistical calculations and tests. The results of these studies should indicate that R results are the same

Re: [R] Subset dataframe based on condition

2006-04-17 Thread Tony Plate
help by distilling your problem to a simple example that can be tried out by others. -- Tony Plate Sachin J wrote: Hi, I am trying to extract subset of data from my original data frame based on some condition. For example : (mydf -original data frame, submydf - subset dada frame

Re: [R] test for end of file on connection

2004-05-11 Thread Tony Plate
end of file. AFAIK the other file reading functions have similar behavior. It's still worth reading in detail the help for readLines(). hope this helps, Tony Plate At Tuesday 12:08 AM 5/11/2004, Vadim Ogranovich wrote: Hi, I am looking for a function to test for end-of-file on a connection

Re: [R] privileged slots,

2004-06-03 Thread Tony Plate
is automated testing. I highly recommend it. R comes with a testing framework. -- Tony Plate cheers, jari oksanen -- Jari Oksanen [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] Importing binary data

2004-06-03 Thread Tony Plate
Probably the simplest way to improve the speed of your code would be to write the data so that all the data in a column is contiguous. Then you'll be able to read each column with a single call to readBin(). hope this helps, Tony Plate At Tuesday 04:02 AM 6/1/2004, Uli Tuerk wrote: Hi

Re: [R] How to Describe R to Finance People

2004-06-08 Thread Tony Plate
than it needs to be. Yup, that's why I proposed (and provided an implementation) of an alternative $$ operator that did report an error when object$$name didn't have a name component (and also didn't allow abbreviation), but there was no interest shown in incorporating this into R. -- Tony Plate

Re: [R] direct data frame entry

2004-06-09 Thread Tony Plate
easy to do it by column: d - data.frame(name=c(obs1name,obs2name,obs3name),val1=c(0.2,0.4,0.6),val2=c(0.3,1.0,2.0),row.names=c(r1,r2,r3)) d name val1 val2 r1 obs1name 0.2 0.3 r2 obs2name 0.4 1.0 r3 obs3name 0.6 2.0 (when you do it by row, you get the numbers as factors because

Re: [R] a scope problem

2004-06-10 Thread Tony Plate
This looks like it probably is a scope problem with non-standard evaluation rules for the argument subset= of nnet. Instead of subset=sub[-i], try data=dftc[-i,] (I've not tested this since I don't have the data objects you used.) hope this helps, Tony Plate At Thursday 04:38 PM 6/10/2004

Re: [R] Elementary sapply question

2004-06-21 Thread Tony Plate
rules result in the arguments having the values y=3, x=1. hope this help, Tony Plate Thanks, -ans. -- Ajay Shah Consultant [EMAIL PROTECTED] Department of Economic Affairs http://www.mayin.org/ajayshah

Re: [R] Re: summaries (was: SUMMARY: elementary sapply question)

2004-06-24 Thread Tony Plate
-hamburg.de/cgi-bin/Rwiki.pl?RwikiHome yet no one really used it. Some critical mass of use is needed to get such a project off the ground. Comments? -- Tony Plate __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do

Re: [R] naive question

2004-06-30 Thread Tony Plate
, then, as others have suggested, writing a C program wouldn't be that hard, as long as you make the format inflexible. -- Tony Plate At Tuesday 06:19 PM 6/29/2004, Igor Rivin wrote: I was not particularly annoyed, just disappointed, since R seems like a much better thing than SAS in general, and doing

Re: [R] naive question

2004-06-30 Thread Tony Plate
source volunteer project suggests that the time is ripe for one of those disappointed people to fix the matter and contribute the function read.table.fast()! -- Tony Plate At Wednesday 10:08 AM 6/30/2004, Igor Rivin wrote: Thank you! It's interesting about S-Plus, since they apparently try to support

Re: [R] Can R read data from stdin?

2004-07-09 Thread Tony Plate
The easiest way would probably be to do the hack of creating a temporary file to hold stdin, then call R to process that file. That would be easy to do in a shell script. If this really won't suffice, this older message might lead to something useful: Rd] R scripting patches for R-1.8.0 Neil

Re: [R] Regular Expressions

2004-07-12 Thread Tony Plate
- table(unlist(sapply(c(perl,program,thomas), function(re) grep(re, x)), use.names=F)) y 2 3 4 1 3 2 which(y=2) 3 4 2 3 hope this helps, Tony Plate At Monday 05:59 PM 7/12/2004, Sangick Jeon wrote: Hi, Is there a way to use regular expressions to capture two or more words in a sentence

Re: [R] Stumped with subsetting

2004-07-29 Thread Tony Plate
[,mylist] x y 1 1 4 2 2 5 3 3 6 I'd generally use the second form of subsetting above (i.e., data[,mylist], because that will work with matrices as well). hope this helps, Tony Plate At Thursday 01:22 PM 7/29/2004, Peter Wilkinson wrote: This seems like such a trivial thing to do: given

Re: [R] lapply drops colnames

2004-08-02 Thread Tony Plate
, x2) [1] TRUE hope this helps, Tony Plate At Monday 04:35 PM 8/2/2004, Jack Tanner wrote: Wolski wrote: What you can do is to extend the column (list) by an addtional attribute attr(mydataframe[i],info)-names(mydataframe)[i] and store theyr names in it. OK, that's brilliant. Any ideas on how

Re: [R] How to import specific column(s) using read.table?

2004-08-10 Thread Tony Plate
.: rep(NULL, 20) NULL c(rep(list(NULL), 3), rep(list(0), 2)) [[1]]: NULL [[2]]: NULL [[3]]: NULL [[4]]: [1] 0 [[5]]: [1] 0 Tony Plate But anyway, it works and saves a lot of memory for me. Thank you again. Frank Quoting Gabor Grothendieck [EMAIL PROTECTED]: Gabor Grothendieck ggrothendieck

RE: [R] numerical accuracy, dumb question

2004-08-14 Thread Tony Plate
/1000 [1] 20.028 So, for long vectors with relatively few different values, storage as factors is far more memory efficient (this is because the character data is stored only once per level, and each element is stored as a 4-byte integer). (The above was done on Windows 2000). -- Tony Plate

Re: [R] Suggestion for posting guide

2004-08-20 Thread Tony Plate
gets put on the R-project site might be willing to put it up there, and a link to it from the posting guide would seem like a good idea. Tony Plate At Thursday 07:17 AM 8/19/2004, Gabor Grothendieck wrote: I have a suggestion for the posting guide. One problem with some posts is that they do

Re: [R] Loss of rownames and colnames

2004-08-20 Thread Tony Plate
,each=26),letters,sep=), LETTERS)) dim(x) [1] 1757626 xr - sample(rownames(x), 1) length(xr) [1] 1 system.time(y - x[xr, ]) [1] 2.22 0.00 2.30 NA NA system.time(y - x[match(xr, rownames(x)), ]) [1] 0.09 0.00 0.09 NA NA HTH -- Tony Plate My bad workaround solution so far

Re: [R] apply ( , , table)

2004-08-24 Thread Tony Plate
001 30100 40220 50011 61001 71000 80010 90000 hope this helps, Tony Plate At Tuesday 10:42 AM 8/24/2004, [EMAIL PROTECTED] wrote: a - matrix (c( 7, 1, 1, 2, 6, 3, 4, 0

Re: [R] (no subject)

2004-08-24 Thread Tony Plate
that this method returns the first max value in the case of ties. hope this helps, Tony Plate At Tuesday 11:01 AM 8/24/2004, Jonathan Baron wrote: On 08/24/04 13:50, Paolo Tommasini wrote: Hi my name is Paolo Tommasini does anyone know how to compute a mode ( most frequent element ) for a distribution

Re: [R] S - R

2004-08-25 Thread Tony Plate
dumps from S-PLUS 5.x and 6.x written with data.dump(oldStyle=T). -- Tony Plate At Wednesday 10:29 AM 8/25/2004, Zachary Skrivanek wrote: Hello! I would like to be able to read in list data objects in R/S created in R/S. (Ie R-S or S-R.) I have tried 'dput' and 'dump' in S, but neither

Re: [R] S - R

2004-08-25 Thread Tony Plate
foreign loaded R data.restore(junk2.dat) Error in ReadSdump(TRUE, ) : S mode junk (near byte offset 45) not supported In addition: Warning message: NAs introduced by coercion R data.restore(junk3.dat) [1] junk3.dat R junk $f g -- Tony Plate At Wednesday 11:45 AM 8/25/2004, Rolf Turner wrote: I'm

Re: [R] terminate R program when trying to access out-of-bounds array element?

2005-04-13 Thread Tony Plate
into the subsetting methods for those classes -- you can't just use the above approach. hope this helps, Tony Plate Vivek Rao wrote: I want R to stop running a script (after printing an error message) when an array subscript larger than the length of the array is used, for example x = c(1) print(x[2

Re: [R] terminate R program when trying to access out-of-bounds array element?

2005-04-13 Thread Tony Plate
Oops. The message in the 'stop' should be something more like numeric index out of range. -- Tony Plate Tony Plate wrote: One way could be to make a special class with an indexing method that checks for out-of-bounds numeric indices. Here's an example for vectors: setOldClass(c(oobcvec

[R] pointer to comments re Paul Murrell's new book, R, SAS on Andrew Gelman's blog

2005-04-21 Thread Tony Plate
There are some interesting comments re Paul Murrell's new book, R, SAS on Andrew Gelman's blog: http://www.stat.columbia.edu/~cook/movabletype/archives/2005/04/a_new_book_on_r.html -- Tony Plate __ R-help@stat.math.ethz.ch mailing list https

Re: [R] Proba( Ut+2=1 / ((Ut+1==1) (Ut==1))) ?

2005-04-25 Thread Tony Plate
table() can return all the n-gram statistics, e.g.: v - sample(c(-1,1), 1000, rep=TRUE) table(v_{t-2}=v[-seq(to=length(v), len=2)], v_{t-1}=v[-c(1,length(v))], v_t=v[-(1:2)]) , , v_t = -1 v_{t-1} v_{t-2} -1 1 -1 136 134 1 131 112 , , v_t = 1 v_{t-1} v_{t-2} -1 1

Re: [R] Index matrix to pick elements from 3-dimensional matrix

2005-04-26 Thread Tony Plate
-- Tony Plate Robin Hankin wrote: Hello Juhana try this (but there must be a better way!) stratified.select - function(A,J){ out - sapply(J,function(i){sample(A[,,i],1)}) attributes(out) - attributes(J) return(out) } A - array(letters[1:12],c(2,2,3)) J - matrix(c(1,2,3,3),2,2) R stratified.select

Re: [R] Summarizing factor data in table?

2005-04-26 Thread Tony Plate
Do you want to count the number of non-NA divisions and organizations in the data for each year (where duplicates are counted as many times as they appear)? tapply(!is.na(foo$div), foo$yr, sum) 1998 1999 2000 042 tapply(!is.na(foo$org), foo$yr, sum) 1998 1999 2000 442

Re: [R] Defining binary indexing operators

2005-04-27 Thread Tony Plate
function: foo(x,y) uses the value of the variable 'y', whereas x$y uses the string y. This is as desired for an indexing operator $. -- Tony Plate Gabor Grothendieck wrote: On 4/27/05, Ali - [EMAIL PROTECTED] wrote: Assume we have a function like: foo - function(x, y) how is it possible to define

Re: [R] Defining binary indexing operators

2005-04-27 Thread Tony Plate
Excuse me! I misunderstood the question, and indeed, it is necessary be that complicated when you try to make x$y behave the same as foo(x,y), rather than foo(x,y) (doing the former would be inadvisible, as I think someelse pointed out too.) Tony Plate wrote: It's not necessary

Re: [R] Getting the name of an object as character

2005-04-28 Thread Tony Plate
great, but when it doesn't, users can get quite confused trying to figure out what it's doing.) The R function help() is an example of a commonly used function with a non-standard evaluation rule. -- Tony Plate Ali - wrote: This could be really trivial, but I cannot find the right function

Re: [R] Reconstruction of a valid expression within a function

2005-04-28 Thread Tony Plate
() work for you without trying to paste together R language expressions. Hope this helps, -- Tony Plate Pascal Boisson wrote: Hello all, I have some trouble in reconstructing a valid expression within a function, here is my question. I am building a function : SUB-function(DF,subset=TRUE) { #where DF

Re: [R] Subarrays

2005-04-29 Thread Tony Plate
(1,3,4),1,2)) [,1] [,2] [,3] [,4] [1,] 65 69 73 77 [2,] 67 71 75 79 [3,] 68 72 76 80 Question for language experts: is this the best way to create and manipulate R language expressions that contain empty arguments, or are there other preferred ways? -- Tony Plate Gunnar

Re: [R] na.action

2005-04-29 Thread Tony Plate
(and the least versatile). A more general building block is the sum() function, as in: sum(x[3,]==2, na.rm=T) [1] 1 The key is the use of the 'na.rm=T' argument value. hope this helps, Tony Plate Tim Smith wrote: Hi, I had the following code: testp - rcorr(t(datcm1),type = pearson) mat1 - testp

Re: [R] summary(as.factor(x) - force to not sort the result according factor levels

2005-05-02 Thread Tony Plate
Christoph Lehmann wrote: Hi The result of a summary(as.factor(x)) (see example below) call is sorted according to the factor level. How can I get the result not sorted but in the original order of the levels in x? by creating the factor with the levels in the order you want: test - c(120402,

Re: [R] function for cumulative occurrence of elements

2005-06-28 Thread Tony Plate
2 table(doc) doc 1 2 3 9 5 3 hope this helps, Tony Plate Steven K Friedman wrote: Hello, I have a data set with 9700 records, and 7 parameters. The data were collected for a survey of forest communities. Sample plots (1009) and species (139) are included in this data set. I need

Re: [R] Generating correlated data from uniform distribution

2005-07-01 Thread Tony Plate
% 75%100% 0.000655829 0.246216035 0.507075912 0.745158441 0.16418 quantile(dat2[2,]) 0% 25% 50% 75% 100% 0.0393046 0.4980066 0.7150426 0.9208855 1.3864704 -- Tony Plate Jim Brennan wrote: dat-matrix(runif(2000),2,1000) rho-.77 R-matrix(c(1

Re: [R] how as.numeric() !- factor

2003-08-03 Thread Tony Plate
), Np.occup97.98 = sums$Ant.Nptrad97.98/Ant.trad$Ant.trad97.98) (unless of course you had some unstated reason for constructing the data frame the way you did) -- Tony Plate At Thursday 10:03 AM 7/31/2003 +0200, Tord Snall wrote: Dear all, I have divided two vectors: Np.occup97.98- as.data.frame

Re: [R] vectorization question

2003-08-14 Thread Tony Plate
From ?data.frame: Details: A data frame is a list of variables of the same length with unique row names, given class `data.frame'. Your example constructs an object that does not conform to the definition of a data frame (the new column is not the same length as the old columns).

Re: [R] Variance Computing- - HELP!!!!!!!!!!!!!!!!!!

2003-08-19 Thread Tony Plate
Perhaps you were trying for as sample size increases, variance *of the mean* decreases (a least when variance is finite). If you swap mean and var in your code, I think you will get what you are looking for. -- Tony Plate At Tuesday 05:42 PM 8/19/2003 +, Padmanabhan, Sudharsha wrote

Re: [R] Using files as connections

2003-08-28 Thread Tony Plate
this helps, Tony Plate At Thursday 11:19 AM 8/28/2003 +1200, you wrote: I have been trying to read a random sample of lines from a file into a data frame using readLines(). The help indicates that readLines() will start from the current line if the connection is open, but presented with a closed

Re: Just don't do it, surely? (was RE: [R] Retrieve ... argument values)

2003-09-17 Thread Tony Plate
to get the lower-level default behavior. -- Tony Plate __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

RE: Just don't do it, surely? (was RE: [R] Retrieve ... argument values)

2003-09-17 Thread Tony Plate
defaults for an argument of the same name, it can certainly be handled as you describe by making different argument names in the higher level function. -- Tony Plate At Wednesday 05:25 PM 9/17/2003 +0100, Simon Fear wrote: Tony, I don't understand what you mean. Could you give an example

Re: AW: [R] Rank and extract data from a series

2003-09-23 Thread Tony Plate
, decreasing=TRUE)[1:2])) [1] 3.67 which(X %in% sort(X, decreasing=TRUE)[1:2]) [1] 2 4 5 # Thomas Unternährer's suggestion: mean(match(sort(X, decreasing=TRUE)[1:2], X)) [1] 3.5 match(sort(X, decreasing=TRUE)[1:2], X) [1] 5 2 hope this helps, Tony Plate At Tuesday 02:23 PM 9/23/2003 +0200

Re: [R] confusion about what to expect?

2003-09-23 Thread Tony Plate
not in a quick look through the FAQ, ?[, and An Introduction to R -- please excuse me if I overlooked something.) The thing you have going on with names(testdata[...]) is merely a consequence of whether or not the result of the subsetting operation is a dataframe or a vector. hope this helps, Tony Plate

Re: [R] Why does a[which(b == c[d])] not work?

2003-10-08 Thread Tony Plate
] 2 4 Sometimes one might want the first result, but more usually, I want the second, and using which() seems a convenient way to get it. -- Tony Plate __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Re: AW: [R] Getting rows from a dataframe

2003-10-09 Thread Tony Plate
, this will be a character vector) as.matrix(x)[2,] a b 2 5 # row as a numeric vector (non-numeric columns in x will be converted to numeric data, see ?data.matrix for how) data.matrix(x[2,]) a b 2 2 5 Tony Plate At Thursday 05:40 PM 10/9/2003 +0100, Mark Lee wrote: I have this right

Re: [R] Subseting in a 3D array

2003-10-15 Thread Tony Plate
One way would be: apply(ib5km.lincol.random[1:3,], 1, function(i) ib5km15.dbc[i[1],i[2],]) (untested) -- Tony Plate At Wednesday 06:47 PM 10/15/2003 +0200, Agustin Lobo wrote: Hi! I have a 3d array: dim(ib5km15.dbc) [1] 190 241 19 and a set of positions to extract: ib5km.lincol.random[1

Re: [R] datetime data and plotting

2003-10-17 Thread Tony Plate
the usefulness of a time-zone-free time/date class, but why does chron need to be moved to the base to be useful here? -- Tony Plate __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help

Re: [R] do.call() and aperm()

2003-10-21 Thread Tony Plate
() automatically calculate along=length(dim)+1 when given along=NA, or along=-1, or along=+1. Any preferences? -- Tony Plate At Tuesday 04:48 PM 10/21/2003 +0100, Robin Hankin wrote: Hi everyone I've been playing with do.call() but I'm having problems understanding it. I have a list of n elements, each one

Re: [R] do.call() and aperm()

2003-10-21 Thread Tony Plate
do.call(abind c(list.of.arrays, list(along=4))) This reminds me that I had been meaning to submit an enhancement of abind() that allows the first argument to be a list of arrays so that you could simply do abind(list.of.arrays, along=4), as I find this is a very common pattern. -- Tony Plate

Re: [R] do.call() and aperm()

2003-10-21 Thread Tony Plate
Thanks, I appreciate knowing that. abind() can currently take a fractional value for along, and behaves as per your description of 'catenation' in APL. Does APL supply any hints as to what sort of value to give 'along' to tell abind() to perform 'lamination'? -- Tony Plate At Tuesday 01:22

[R] what's going on here with substitute() ?

2003-10-23 Thread Tony Plate
what's going here.) -- Tony Plate PS. In S-plus 6.1, things worked as I had expected: substitute(this.is.R - function() X, list(X=!is.null(options(CRAN)[[1]]))) this.is.R - function() F eval(substitute(this.is.R - function() X, list(X=!is.null(options(CRAN)[[1]] function() F this.is.R

  1   2   >