Re: [R] Calculating distance between longitude, latitude of 2 points

2010-11-19 Thread MacQueen, Don
Also spDists spDistsN1 Euclidean or Great Circle distance between points In the sp package. (and in my personal opinion, the sp package would be a good place to start, since it’s part of a group of packages I view as R’s core packages for working with spatial data) -Don On 11/19/10

Re: [R] small problem in coding

2010-11-26 Thread MacQueen, Don
As Nick suggested, you're confusing the name of an object with the name(s) of its elements. Study this example: lamda - 0.2 lamda [1] 0.2 lamda - c(g=0.2) lamda g 0.2 lamda - c(1,3,4) lamda [1] 1 3 4 lamda - c(g=1, x=3, foo=4) lamda g x foo 1 3 4 lamda is now a

Re: [R] How to create sequence in month

2010-07-12 Thread MacQueen, Don
As in this example: seq(as.Date(2000/1/1), as.Date(2003/1/1), by=mon) On 7/12/10 11:25 AM, Bogaso Christofer bogaso.christo...@gmail.com wrote: Hi all, can anyone please guide me how to create a sequence of months? Here I have tried following however couldn't get success

Re: [R] a issue about the qutation mark?

2010-07-16 Thread MacQueen, Don
You need to understand the difference between a variable and a value. In your case that doesn't work, you are supplying a value, trait.value. but you have no file named trait.value. In the case that does work you are supplying a variable, trait.value, and the value contained in that variable is

Re: [R] time in year, month, day, hour ?

2010-09-30 Thread MacQueen, Don
Here is an example of how I would do it. Just replace my ‘indx’ with the values in your first column. indx - 1:13 t0 - as.POSIXct('2009-01-01 00:00') tms - t0 + (indx -1 )* 3 * 60 * 60 tms [1] 2009-01-01 00:00:00 PST 2009-01-01 03:00:00 PST [3] 2009-01-01 06:00:00 PST 2009-01-01 09:00:00

Re: [R] Converting a dataframe column from string to datetime

2010-10-01 Thread MacQueen, Don
You’re working too hard. Use this: tms - as.POSIXct(strptime(v, %a %b %d %H:%M:%OS %Y)) Take note of the fact that there are two types of datetime objects: POSIXct and POSIXlt. Your unlist() gave what seemed a strange result because you used on an “lt” object. Had you given it a “ct”

Re: [R] Using as.polynomial() over a matrix

2010-10-05 Thread MacQueen, Don
The key is in the help page for apply. It says (in part): In all cases the result is coerced by Œas.vector¹ to one of the basic vector types before the dimensions are set, so that (for example) factor results will be coerced to a character array. So although as.polynomial()

Re: [R] Using as.polynomial() over a matrix

2010-10-06 Thread MacQueen, Don
Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of MacQueen, Don Sent: Wednesday, 6 October 2010 1:23 PM To: Raznahan, Armin (NIH/NIMH) [E]; r-help@r-project.org Subject: Re: [R] Using as.polynomial() over a matrix The key is in the help page

Re: [R] select columns from vector of column names

2010-07-09 Thread MacQueen, Don
How about data[ , colnames] Or data[ , colnames[1]] data[ , colnames[2]] -Don On 7/9/10 11:27 AM, Jonathan Flowers jonathanmflow...@gmail.com wrote: Hi I want to extract columns from a data frame using a vector with the desired column names. This short example uses the select

Re: [R] wrong name of input file and goto like function

2011-07-25 Thread MacQueen, Don
While you study the documentation as others suggested, may I suggest that you take a look at the file.exists() function. Here is an example of using file.exists(). tmpfile - define() if (file.exists(tmpfile)) { ## read the file } else { ## tell the user to try again } On Jul 24, 2011, at

Re: [R] extracting file names

2011-03-25 Thread MacQueen, Don
While I think David's suggestion is better, because it's more readable, this should also work: dat - read.table(file.name - file.choose(), header = FALSE) Note the assignment inside the function call. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627

Re: [R] Grid on Map

2011-04-06 Thread MacQueen, Don
Possibly something similar to abline(v=seq(long.min, long.max, length=3) abline(h=seq(lat.min, lat.max, length=3) ? The above will add vertical and horizontal lines to an existing plot, and assumes that the plot is in long/lat coordinates. Of course, this ignores the fact that long/lat is

Re: [R] problem with all/all.equal

2011-04-13 Thread MacQueen, Don
The help pages for identical() and all.equal() have information that will make it clear why they don't do what you want. In the meantime, I tend to use a construct such as: length(unique(x))==1 But be careful if x is not a vector. No doubt there are other ways. -Don -- Don MacQueen

Re: [R] Monte Carlo Simulation

2011-04-15 Thread MacQueen, Don
See below: -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 -Original Message- From: Jeremy Miles jeremy.mi...@gmail.com Date: Fri, 15 Apr 2011 14:17:13 -0700 To: Shane Phillips sphill...@lexington1.net Cc:

Re: [R] Monte Carlo Simulation

2011-04-15 Thread MacQueen, Don
The filenames can be done within a loop, like this: for (id in 1:1000) { ## the filename fname - paste('sample', formatC(id,width=4,flag='0'),'.tsv',sep='') ## more stuff } -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550

Re: [R] Split data frame by date (POSIXlt)

2011-08-25 Thread MacQueen, Don
I suspect, but have not tested, that your src$date element has class POSIXlt, which is internally a list, in which case splitting by it might not work properly, and might be the cause of your out of bounds error message. One of these might do the job: src$date -

Re: [R] how to split a data frame by two variables

2011-09-01 Thread MacQueen, Don
Even though it's not needed, here's a small followup. I usually use this split(x, paste(x$let,x$g)) But since split(x, list(x$let,x$g)) works, so does split(x, x[,c('let','g')]) all.equal( split(x, x[,c('let','g')]) , split(x,list(x$let,x$g))) [1] TRUE As to which is the best, hard

Re: [R] help subsetting data based on date AND time

2011-09-08 Thread MacQueen, Don
Steve, Just below are some examples that I hope will help. With regard to what you've tried, I don't see any reason for using with(), or the select argument to subset(). They both look unnecessary to me. ## examples of subsetting date-time values ## create fake data tmp -

Re: [R] Moving data in a dataset

2011-09-14 Thread MacQueen, Don
Spreadsheets have cells, but R does not. So you will have to be much more specific. The closest I can come would be like this example: If you want to copy the value that is in the 3rd row, 2nd column to the 4th row, 1st column, then mydata[4,1] - mydata[3,2] But that is a copy, not a move (and

Re: [R] Mystified - comparing chron times

2011-09-16 Thread MacQueen, Don
Not that anything more needs to be said ... it doesn't, not really ... But I think that in cases like this it is helpful to use the digits arg to print(). It probably would have shown in a simple way that the two numeric versions aren't really equal -- and demonstrated a little about R's default

Re: [R] Problematic If-Else statement

2011-09-16 Thread MacQueen, Don
It's probably not a sensible thing to do, but I'm going to guess. With a name like days_to_tumor_recurrence, I might expect numeric (integer) values. But null and numeric don't mix. as.numeric(c('24','null',23')) will return 24, NA, 23. There may have been such a conversion in the preparation

Re: [R] Help writing basic loop

2011-09-16 Thread MacQueen, Don
Just a minor aside; I would have done my.slopes - numeric(100) Note that: class(numeric(5)) [1] numeric -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 9/16/11 12:37 PM, Luke Miller mille...@gmail.com wrote:

Re: [R] R package built with Fortran code

2012-02-22 Thread MacQueen, Don
As far as I know, you must convert your main program into a subroutine. In my experience, this consist mostly if not entirely of converting user input from prompts to subroutine arguments. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550

Re: [R] how to merge commands

2012-02-22 Thread MacQueen, Don
Are you absolutely certain that the data must be stored in Excel? In the long run I believe you will find it easier if the data is stored in an external database, or some other data repository that does not require you to read so many separate files. Probably the best you can hope for as it is

Re: [R] How can I save plot()/points() using SHP files into KML format?

2012-03-14 Thread MacQueen, Don
Since you found readOGR, you might want to look at writeOGR. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/22/12 3:43 PM, gztourek gztou...@gmail.com wrote: Hi, I am new to R and am a very basic user. I'm

Re: [R] POSIXlt vs POSIXct

2012-03-29 Thread MacQueen, Don
I also find that POSIXct is generally the most useful, and only use POSIXlt in special cases. But have you considered as.POSIXct() instead of strptime()? It works for me, and I can't remember the last time I had to use strptime() for converting character to date/time. (But I mostly don't work

Re: [R] Is it possible to de-select with sqlQuery from the RODBC library?

2012-04-02 Thread MacQueen, Don
I've never heard of a an SQL de-select, but if there is such a thing it shouldn't be too hard to find via some web searches. In the meantime, I would probably just do a select * to get all the fields from the database tables, and then drop the unwanted ones afterwards in R. I think this will give

Re: [R] Trying to understand factors

2012-04-04 Thread MacQueen, Don
I'd like to make the distinction between the purpose of factors, i.e., what they are intended for, and how that purpose is accomplished. Their purpose is for use in statistical models. The simplest example is analysis of variance, where predictors are commonly referred to as factors. Factors in R

Re: [R] Filling empty List in a FOR LOOP

2012-04-04 Thread MacQueen, Don
Try A[[1]] - NA (It is of course up to you to do the tests, presumably using if(), to decide when to assign NA to the list element.) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 3/31/12 7:53 PM, michaelyb

Re: [R] recover lost global function

2012-04-05 Thread MacQueen, Don
To expand on Duncan's answer, you haven't replaced it. The following should make that clear: ## starting in a fresh session c function (..., recursive = FALSE) .Primitive(c) find('c') [1] package:base c - 1 find('c') [1] .GlobalEnv package:base c [1] 1 rm(c) find('c') [1] package:base

Re: [R] What are the necessary Oracle software to install and run ROracle ?

2011-01-06 Thread MacQueen, Don
Have you run genclntsh and/or genclntst In ORACLE_HOME/bin ? I don’t recall very well where I learned about this, or how it is documented... But it does something to some files in $ORACLE_HOME/lib that is needed in order for Roracle to build. lib[598]% nm libclntsh.so | grep sqlprc

Re: [R] Inconsisten graphics i/o when using Rscript versus GUI

2011-01-21 Thread MacQueen, Don
John, The first thing I would do is create a simpler example, i.e., to help isolate the issue. Here’s a simple example: The contents of a file are: #! /usr/bin/Rscript pdf('test1.pdf') plot(1:10) dev.off() pdf('test2.pdf') plot(10:1) dev.off()

Re: [R] merge tables in a loop

2011-01-26 Thread MacQueen, Don
Not sure exactly what you mean by, “ writing a table with several rows per file”. If what you want to do is write output to an external file, adding to it as your loop progresses, then look at the functions sink() cat() And their ‘file’ and ‘append’ arguments. If what you want to do is

Re: [R] SpatialLines

2011-10-26 Thread MacQueen, Don
In addition to which, R-sig-geo would be better place to ask. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 10/26/11 10:39 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 26/10/2011 1:11 PM, Mark Newcomb wrote:

Re: [R] NROW doesn't equal length(x)

2011-10-28 Thread MacQueen, Don
And to further the example, length() of matrix is not equal to the number of rows either. mm - matrix(1:6, ncol=2) length(mm) [1] 6 dim(mm) [1] 3 2 Also, NROW() and nrow() are different; I'd be cautious about using NROW without making sure I understood the difference. NROW function (x) if

Re: [R] Email out of R (code)

2011-10-28 Thread MacQueen, Don
The various suggestions seem kind of complex to me, at least on a unix-like system (including Mac OS X). This is what I do: sink('tmp.txt') cat('This is the body of the message\n') sink() system('cat tmp.txt | mail -s A test email macque...@llnl.gov') One could probably avoid the

Re: [R] HELP DATA CLIPPING AND DATA OVERLAY ON A MAP

2011-11-16 Thread MacQueen, Don
I would suggest starting by taking a look at the overlay() function in the sp package. (also suggest follow up questions to to R-sig-geo) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/16/11 11:30 AM, Peter Maclean

Re: [R] Interpolating hourly basis

2011-11-16 Thread MacQueen, Don
One option would be, after you have converted one of your date/time variables (V2 I would assume) to POSIXct class, you can use the interp() function in the akima package for linear interpolation between adjacent time points. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000

Re: [R] Numerical Format on axis

2011-11-16 Thread MacQueen, Don
To add to what David suggests, and since you're new to R, something like this: plot(x,y, yaxt='n') yticks - pretty(y) axis(2, at=yticks, labels=sprintf(%1.2f,yticks)) See the help page for par ?par and look for the entry for 'xaxt' to see what the 'yaxt' arg to plot does. -- Don MacQueen

Re: [R] Adding a year to existing date

2011-11-17 Thread MacQueen, Don
Here is an example that could probably be described as adding a year: dates - c('2008-01-01','2009-03-02') tmp - as.POSIXlt(dates)tmp$year - tmp$year+1 dates2 - format(tmp) dates [1] 2008-01-01 2009-03-02 dates2 [1] 2009-01-01 2010-03-02 ## to begin to understand how it works, give the command

Re: [R] Combining data

2011-11-17 Thread MacQueen, Don
There is no single command to do all of what you want. Read the posting guide for advice on how to ask questions that are more likely to receive helpful answers. The mean() function is a command for combining certain number of data into their average value. The write.csv() function will create

Re: [R] tip: large plots

2011-11-22 Thread MacQueen, Don
And even more for the heck of it... this kind of thing is also device-dependent. (this is *not* a controlled test; some variation could be due to other processes running on the machine) -Don x11(type='Xlib') system.time(plot(runif(1e6),runif(1e6))) user system elapsed 0.712 0.165

Re: [R] x, y for point of intersection

2011-11-23 Thread MacQueen, Don
The function crossing.psp() in the spatstat package might be of use. Here's an excerpt from its help page: crossing.psp package:spatstat R Documentation Crossing Points of Two Line Segment PatternsDescription: Finds any crossing points between two line segment patterns.

Re: [R] question about spaces in r

2011-12-09 Thread MacQueen, Don
First of all, it's R, not r, and on this mailing list people care about this kind of thing. Second, you will need to provide more information in order to get better help. Please read the posting guide. There are a number of introductory level documents available via CRAN, please pick one and

Re: [R] windrose color ramp issue

2011-12-14 Thread MacQueen, Don
There is also a windrose (though not with that name) function in the openair package. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 12/12/11 1:20 PM, Adrienne Wootten amwoo...@ncsu.edu wrote: Greetings! I'm having an

Re: [R] write.xls dont find the object in function

2011-12-20 Thread MacQueen, Don
Or: require(xlsx) test - function(x){ +a - data.frame(A=c(1,2),B=c(10,11)) +write.xlsx(a,file=a.xlsx) + } test() list.files(patt='xlsx') [1] a.xlsx -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 12/19/11

Re: [R] try to silence errors

2011-12-22 Thread MacQueen, Don
Something like the following may be what you are looking for. try.out - try(dmt(y[,j],new$mu[,,4],sigij,ceiling(new$nu[4])),silent=TRUE) if (class(try.out) == 'try-error'} ) { out - NaN } else { out - try.out } -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave.,

Re: [R] Create variable with AND IF statement

2012-01-02 Thread MacQueen, Don
I usually do this kind of thing like this: variable3 - rep(1,length(variable1.fac)) variable3[ variable1.fac == 0 variable2.num = 1 ] - 2 variable3[ variable1.fac == 1 variable2.num == 0 ] - 3 variable3[ variable1.fac == 1 variable2.num = 1 ] - 4 This approach is easy to read and understand,

Re: [R] add data to a file while doing a loop

2012-01-06 Thread MacQueen, Don
Look at the documentation for whatever function you are using to write data to the file. It should be pretty obvious (look for an append argument). Otherwise you'll have to provide more information, such as a short simple example of what you have tried. -Don -- Don MacQueen Lawrence Livermore

Re: [R] Spatial data, rpoispp, using window with fixed radius?

2012-01-06 Thread MacQueen, Don
What's wrong with rpoispp in spatstat? It can simulate over a polygon, which can of course be used to closely approximate a circle. There is also spsample in the sp package. I'd also suggest asking this question on r-sig-geo. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East

Re: [R] data.frame: temporal complexity

2012-01-06 Thread MacQueen, Don
Something like this (not tested)? df$diffP - c(NA, NA, diff(df$P,2)) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/6/12 6:39 AM, ikuzar raz...@hotmail.fr wrote: Hello, I created a data.frame which contains two

Re: [R] (Edited) cbind alternate for data frames

2012-01-06 Thread MacQueen, Don
For me, this example runs in a fraction of a second: t1 - data.frame(matrix(rnorm(3e6),ncol=3)) t2 - data.frame(matrix(rnorm(3e6),ncol=3)) t3 - cbind(t1,t2) dim(t3) [1] 100 6 Maybe it takes longer if your data frames have other classes of objects in them. If some of your data frame

Re: [R] splitting strings effriciently

2012-01-09 Thread MacQueen, Don
See suggestion inserted below. It assumes and requires that every input IP address has the required four elements. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/8/12 5:11 AM, Enrico Schumann enricoschum...@yahoo.de

Re: [R] strange Sys.Date() side effect

2012-01-12 Thread MacQueen, Don
My best guess is that you are misunderstanding what the c() function does. I'd suggest reading the help page for c, obtained by typing ?c Note that if you supply c() with objects of different types (as you have), the results will probably not be what you wanted. Given what c() does, your output

Re: [R] Averaging over data sets

2012-01-13 Thread MacQueen, Don
Here is a solution that works for your small example. It might be difficult to prepare your larger data sets to use the same method. db -rbind(d1,d2) aggregate(subset(db,select=-c(subject,trt)), by=list(subject=db$subject),mean) ## or, for example, aggregate(subset(db,select=-c(subject,trt)),

Re: [R] Brillouin index

2012-01-13 Thread MacQueen, Don
It's a pretty simple formula, according to the sources I found. Here's a function that looks right to me, but I have no independent calculation with which to check it. (no guarantees!) Hb - function(ns) { N - sum(ns) (lfactorial(N) - sum(lfactorial(ns)))/N } ns - c(3,5,2,8) Hb(ns) [1]

Re: [R] The Future of R | API to Public Databases

2012-01-13 Thread MacQueen, Don
It's a nice idea, but I wouldn't be optimistic about it happening: Each of these public databases no doubt has its own more or less unique API, and the people likely to know the API well enough to write R code to access any particular database will be specialists in that field. They likely won't

Re: [R] rbind()

2012-01-20 Thread MacQueen, Don
As Sarah said, you have a path problem. Are you saying that RawData is a sub-folder (sub-directory) of SampleProject? And you are running the script with the working directory set to SampleProject? [check using getwd() as Sarah suggested] If so, it looks like it would work if you use

Re: [R] calculating distance between latitude and longitude

2012-01-27 Thread MacQueen, Don
Also spDistsN1() and spDists() in package sp, a perhaps more basic starting point for working with spatial data in R. See also the r-sig-geo mailing list, as well as the CRAN spatial task view. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA

Re: [R] convert sas date format

2012-01-27 Thread MacQueen, Don
Does this do what you want? sasf - c('31.12.1959','1.1.1960','1.2.1960') dt - as.Date(sasf, format='%d.%m.%Y') -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/27/12 7:45 AM, Fischer, Felix

Re: [R] merge multiple data frames

2012-01-27 Thread MacQueen, Don
Not tested, but this might be a case for the sqldf package. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/26/12 9:29 AM, maxbre mbres...@arpa.veneto.it wrote: This is my reproducible example (three data frames: a,

Re: [R] merge multiple data frames

2012-01-30 Thread MacQueen, Don
handle the sql 'as' statement a_b-sqldf(select a.*, b.* from a left join b on a.date=b.date) a_b_c-sqldf(select a_b.*, c.* from a_b left join c on a_b.date=c.date) bye max - Original Message - From: MacQueen, Don macque...@llnl.gov To: maxbre mbres...@arpa.veneto.it; r-help@r

Re: [R] Sensitivity analysis - looking a tool for epidemiologic research

2012-01-30 Thread MacQueen, Don
R has several packages for epidemiology. Maybe one of them has it. Take a look. To name just two: Epi and epitools -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/27/12 9:01 PM, Dominic Comtois

Re: [R] SPATIAL QUESTION: HOW TO MAKE POLYGONS AROUND CLUSTERS OF POINTS AND EXTRACT AREAS AND COORDINATES OF THESE POLYGONS?

2012-02-03 Thread MacQueen, Don
I would suggest asking this question on r-sig-geo. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/3/12 6:59 AM, Bjørn Økland o...@skogoglandskap.no wrote: Imagine that I have a large number of points (given by

Re: [R] X11 error while plotting in R on OSX

2012-02-03 Thread MacQueen, Don
I can't reproduce your error in R 2.14.1 on an OSX 10.6.8 box. However, your example doesn't start with a graphics device specification. Did you start the graphics device with x11() before your first plot() command? If by R on a terminal you mean in Terminal.app, then you wouldn't normally get

Re: [R] sample points - sp package

2012-02-09 Thread MacQueen, Don
I suggest you ask this question on r-sig-geo. And it would be best if you could create a small self-contained example. For example, what class of object is dataset2? Is there any reason to expect that the coordinates of the sample will be exactly the same as any of the coordinates in dataset2?

Re: [R] Subset a datafram according to time

2012-02-09 Thread MacQueen, Don
(apologies in advance for the stupid line-wrapping that I expect my email software to force upon us) If I understand correctly what you want, I would (1) in both data frames, combine date and time into a single column (variable) that is class POSIXct (2) use the merge() function This assumes

Re: [R] Importing a CSV file

2012-02-10 Thread MacQueen, Don
I think you must have given the path to the file wrong. Assuming you are using R.app, try infile - file.choose() And then give infile to the read.csv() function. Then print the value of infile to find out what the path really is. Probably, you wanted

Re: [R] selecting data from table with timestamp

2011-05-11 Thread MacQueen, Don
Try something similar to this: ## unchanged full - read.table(March_15.dat, sep=,,row.names=NULL, as.is=TRUE,skip=1,header=TRUE) ## then convert TIMESTAMP to a date-time class full$TIMESTAMP - as.POSIXct(full$TIMESTAMP) ## now you can use subset() atimeframe - subset(full, TIMESTAMP =

Re: [R] Value of 'pi'

2011-05-30 Thread MacQueen, Don
I once knew someone who thought that a 1-sided upper 99% confidence limit for the mean with n=7 was calculated by multiplying the standard error of the mean by pi. -Don On 5/30/11 6:00 PM, Bentley Coffey bentleygcof...@gmail.com wrote: Pi is an irRATIOnal number, meaning that it is not equal to

Re: [R] Basic loop programming

2013-01-09 Thread MacQueen, Don
Yes, R is a different language, and has different syntax and different built-in functions, so, yes it works differently. If you want to do it the same way in R as in that other language, you have to use a different method for constructing the variable names inside the loop. Here's an example,

Re: [R] putting data.frame values in new dataframes

2013-01-14 Thread MacQueen, Don
Perhaps split(mydf, paste(mydf$month,mydf$day)) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/14/13 5:57 AM, condor radonniko...@hotmail.nl wrote: I have a very dataset which I want to put in new dataframes according

Re: [R] Help regarding kmeans output. need to save the clusters into different directories/folders.

2013-01-24 Thread MacQueen, Don
You find the element of clustering_tail that indicates which which point is in which cluster (the help page for kmeans tells you). Then you use that element to subset your input data (1.tsv). Then you save each subset to a separate folder. By save to a folder I would assume you mean write a tsv

Re: [R] Please help R error message masked from 'package:utils':combn

2013-01-24 Thread MacQueen, Don
After you get that message, use conflicts() (and read the help page for the conflicts function) -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 1/23/13 10:04 PM, Fumie Sugahara fumie.sugah...@gmail.com wrote: Hi

Re: [R] export figure by pdf command

2013-01-30 Thread MacQueen, Don
Works for me, so you will have to provide more information. x11() hist(rnorm(100)) dev.copy2pdf(file='mytest.pdf') X11 2 list.files(patt='mytest') [1] mytest.pdf -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On

Re: [R] Question on plotCI function

2013-02-01 Thread MacQueen, Don
You haven't given any y values to plotCI. Try, for example, plotCI(xx, (lower+upper)/2, ui=upper, (etc) What you got was in effect plot( seq(along=xx), xx ) which is standard behavior for plot() when no y values are supplied. -Don -- Don MacQueen Lawrence Livermore National Laboratory

Re: [R] Modifying Package Data

2013-02-06 Thread MacQueen, Don
My sense is that even if this were possible (which I doubt), it would be outside the scope of what would be considered appropriate in R (assuming I understand the question). After all, it's someone else's package, theirs to control and maintain, etc. What if it's an installation of R on a

Re: [R] Running a R file at a specific time each day

2013-02-11 Thread MacQueen, Don
cron does work just fine on the Mac, and will work the same way as in Linux, except (almost certainly) for the path to R itself. -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/11/13 11:16 AM, Bhupendrasinh Thakre

Re: [R] FORMAT EDITING

2013-02-11 Thread MacQueen, Don
You say, Š use the R output file in Fortran Š I guess that means that R is writing an output file which will then be used as an input file for a fortran program. In that case, you need to go back to how R is writing the output file, find out why it is writing blank lines, and correct it. As far

Re: [R] plot custom x axis ticks values

2013-02-14 Thread MacQueen, Don
plot(testvalues,ann=FALSE,type='l',yaxt='n',xaxt='n') par()$usr [1] 0.88 4.12 8.80 41.20 The x axis range is from 0.88 to 4.12, so tick labels at 0, 100, 200, 300 makes no sense. Any axis() command where the 'at' values are within the range of the x axis will work. Even, for example,

Re: [R] Error in J[time] : invalid subscript type 'closure'

2013-02-27 Thread MacQueen, Don
In my experience, error messages that include the word closure almost always mean that I have tried to do something with a function that isn't supposed to be done with a function (undoubtedly not a technically correct statement, but it works for me). I think that applies here, since time is a

Re: [R] Getting the correct factor level as Dunnett control in glht()

2013-02-27 Thread MacQueen, Don
I think you can probably specify the base level using the contrMat() function, which has a 'base=' argument. Disclaimer: This is a fragment from something I did recently, and is not intended to be reproducible by anyone else. Rather, it is intended to provide a hint as to how to use the

Re: [R] Iteration through a list in R

2013-03-01 Thread MacQueen, Don
I suppose you have your filenames stored in a character vector, which I will name myfiles. (Within R, it is not a list; lists have a special structure). There is no such thing as a tab separated matrix in R. tab separated would refer to the file, I presume. for (nm in myfiles) { tmpdat -

Re: [R] using reserved words in R, and reuse variable names in different functions

2013-03-04 Thread MacQueen, Don
Yes, it can cause problems. And speaking for myself, I'd say it's not worth the risk, because it's easy enough to find alternative variable names that are close enough to the notation of your formulas that remembering should be no problem. For example, tt, cc, and mmatrix might do it. -Don --

Re: [R] issue creating a subset

2013-03-04 Thread MacQueen, Don
What Jim said separately is correct, and I would suggest following his advice. But there are some points worth looking at in your method. See this example: item1 - item2 - item3 - item4 - 1:4 matrix1-cbind(item1, item2, item3, item4) z - c(TRUE,TRUE,FALSE,TRUE) matrix2 -

Re: [R] Version Upgrade and Packages

2013-03-04 Thread MacQueen, Don
Hi Rich, Immediately after you see one of those messages, do, e.g., find('cor') It should tell you that you have more than one object named 'cor' in your search path, and where they all are. Then you can decide if it's what you want (probably not, but can't say from here). -Don -- Don

Re: [R] urgent: question concerning data manipulation

2013-03-04 Thread MacQueen, Don
Here is one way. There will be many ways to do it; I offer this one because it is very general. -Don tmp - split(testdata, testdata$personId) myfun - function(df) { dfo - df if (any(df$law=='SVG')) dfo$svg - 1 else dfo$svg - 0 dfo } tmpo - lapply(tmp,myfun) testout - do.call('rbind',

Re: [R] What package can I use to help me categorize comment responses?

2013-03-04 Thread MacQueen, Don
Daniel, Looking at CRAN, the following might be useful: memiscTools for Management of Survey Data, Graphics, Programming, Statistics, and Simulation questionr Functions to make surveys processing easier surveyanalysis of complex survey samples surveydataTools to

Re: [R] print justify

2013-03-06 Thread MacQueen, Don
I don't know about justify as an arg to print, but the following should qualify as a hint. format(c('a','aa','aaa'), justify='left') [1] a aa aaa tmp - data.frame(a=c('a','aa','aaa')) print(tmp,justify='left') a 1 a 2 aa 3 aaa tmp$b - format(c('a','aa','aaa'),justify='left')

Re: [R] subset columns from list with variable substitution

2012-05-25 Thread MacQueen, Don
Instead of subset(table, select=list1) try table[, list1] However, I suspect you have other problems. Particularly, i is not defined when you use i %in% namelist. You may have wanted i in namelist -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627

Re: [R] subset columns from list with variable substitution

2012-05-25 Thread MacQueen, Don
The select argument to subset() is supposed to name the columns you want to keep. So is the syntax I gave, table[,list1], and it is the correct way when list1 is a character vector (which it is). Your error message says that at least one of the values in list1 is not the name of a column in your

Re: [R] X11 font error on headless server running Xvfb

2012-06-04 Thread MacQueen, Don
You could try the Cairo() device from the Cairo package. It's my understanding (from a time when I was using Xvgb for the same reason) that Cairo does not depend on X Windows. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062

Re: [R] Storing datasets

2012-06-11 Thread MacQueen, Don
This does tend to look like homework, but... If you want them in one vector, then that vector will have length 225*100, of course. So rt(225*100,225) would do it. Or you could use the matrix() function to convert this to a matrix. See ?matrix. -Don -- Don MacQueen Lawrence Livermore National

Re: [R] Define a variable on a non-standard year interval (Water Years)

2012-06-11 Thread MacQueen, Don
Here's one way. (not including the conversion to factor) wdf - data.frame(Date=seq(as.Date(2000/10/1), as.Date(2003/9/30), days)) wdf$wyr - as.numeric(format(wdf$Date,'%Y')) is.nxt - as.numeric(format(wdf$Date,'%m')) %in% 1:9 wdf$wyr[ is.nxt ] - wdf$wyr[is.nxt]-1 ## and you can do some

Re: [R] Storing datasets

2012-06-14 Thread MacQueen, Don
And I'd like to add, just for the purpose of learning about R ... even if wishes to use the loop version, there appears to be a misunderstanding of R syntax. The expression 1:225*100 does not produce 22500 numbers to put into the matrix, as apparently expected. Compare: 1:3*5 [1] 5 10

Re: [R] Interactive Graphics

2012-06-18 Thread MacQueen, Don
As I recall, there is a package that can be used to create interactive svg files. I don't remember its name, but I seem to recall it was fairly easy to find on the CRAN packages page. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550

Re: [R] Installing xlsx package on Mac OS X

2012-06-19 Thread MacQueen, Don
As far as recall (it's been a while), install.packages('xlsx') worked for me, on a 10.6 system. You'll have to provide more information. And probably it would be better to take this to R-sig-mac. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore,

[R] Format text with outline?

2012-06-19 Thread MacQueen, Don
I'm using mtext() to annotate a plot. I would like, if possible, to have the individual characters formatted with an outline or border, with a contrasting fill color inside the borders. I'd appreciate suggestions or pointers toward a way to do this. The reason is because I'm creating a graphic

Re: [R] Format text with outline?

2012-06-19 Thread MacQueen, Don
/control-font-thickness-without- changing-font-size and http://stackoverflow.com/questions/10686054/outlined-text-with-ggplot2 which refers to a base graphics version. HTH, b. On 20 June 2012 07:58, MacQueen, Don macque...@llnl.gov wrote: I'm using mtext() to annotate a plot. I would like

Re: [R] number of items to replace is not a multiple of replacement length

2012-06-29 Thread MacQueen, Don
Here is an example to use as a starting point for what that error message means. x - 1:6 x[1:5] - 1:2 Warning message: In x[1:5] - 1:2 : number of items to replace is not a multiple of replacement length The expression x[1:5] - means that we are about to replace the first five elements

  1   2   3   4   5   6   >