Kirsten Beyer | 4 Jul 03:06

comparing matrix and vector and flagging matches

Hello,

I am using the ppswr function to perform probability proportional to size
sampling for a list of subjects, which returns the indices of the rows
sampled from a given matrix (of census blocks).  (e.g. 2,5,29,8, 29... rows
2, 5 and 8 are chosen once and row 29 is chosen twice for a particular
subject).  I would like to compare these indices returned from the ppswr
function to the original table and add a new variable to the original table
to indicate how many times a row was selected.  The sampling procedure needs
to happen once for each of 10,000 subjects, so must be within a loop.
Advice appreciated!

K

	[[alternative HTML version deleted]]

Ben Bolker | 4 Jul 01:11
Favicon

Re: Simple one


JoK LoQ wrote:
> 
> Just a quickly beginner's question. 
> 
> I wanna find the mean only from the values from a column related to
> specific values from another one. Like, theres a 'region' column, i want
> the mean of the value on 'profit' column only from "south" sells from
> 'region' column
> 

mean(x[x$region=="south",]$profit)

or  (untested)

mean(subset(x,region=="south",select=profit))
--

-- 
View this message in context: http://www.nabble.com/Simple-one-tp24329691p24329808.html
Sent from the R help mailing list archive at Nabble.com.

Lars Bishop | 4 Jul 00:45

Error using the Rdonlp2‏ Package

Dear experts,

I'm attempting to solve a constrained optimization problem using the Rdonlp2
package.

I created a Lagrange function (L=f(x)-lambda(g(x)-c)), where x is a vector
of 16 parameters. This is what I'm using as objective function in the code
below. In addition, I set bounds on these parameters (par.u and par.l). When
I run the code, I get the error message shown below. Any idea why or what
does it mean?

Thanks in advance for your help!

 ans <- donlp2(par=rate0, fn=L,par.u=par.u, par.l=par.l)

   1 fx=   2.869234e+08 upsi=  0.0e+00 b2n=  5.0e+08 umi=  0.0e+00 nr   0
si-1
   2 fx=  -2.111002e+09 upsi=  0.0e+00 b2n=  5.1e+08 umi=  0.0e+00 nr  14
si-1
   3 fx=  -5.961701e+09 upsi=  0.0e+00 b2n=  4.1e+08 umi=  0.0e+00 nr  16
si-1

*Error Message:*

Error in tryCatchList(expr, classes, parentenv, handlers) :
  SET_VECTOR_ELT() can only be applied to a 'list', not a 'character'

	[[alternative HTML version deleted]]

(Continue reading)

Ted Byers | 3 Jul 23:45

The time series analysis functions/packages don't seem to like my data

I have hundreds of megabytes of price data time series, and perl
scripts that extract it to tab delimited files (I have C++ programs
that must analyse this data too, so I get Perl to extract it rather
than have multiple connections to the DB).

I can read the data into an R object without any problems.

thedata = read.csv("K:\\Work\\SignalTest\\BP.csv", sep = "\t", header
= FALSE, na.strings="")
thedata

The above statements give me precisely what I expect.  The last few
lines of output are:
8190 2009-06-16 49.30
8191 2009-06-17 48.40
8192 2009-06-18 47.72
8193 2009-06-19 48.83
8194 2009-06-22 46.85
8195 2009-06-23 47.11
8196 2009-06-24 46.97
8197 2009-06-25 47.43

I have loaded Rmetrics and PerformanceAnalytics, among other packages.
 I tried as.timeseries, but R2.9.1 tells me there is no such function.
I tried as.ts(thedata), but that only replaces the date field by the
row label in 'thedata'.

If I apply the performance analytics drawdowns function to either
thedata or thedate$V2, I get errors:
> table.Drawdowns(thedata,top = 10)
(Continue reading)

Mark Knecht | 3 Jul 22:11

Multi-line plots - max Y?

Hi all,
   OK, I'm struggling a bit with getting good basic plots so I put
together this little example. It works - sort of - but it seems a bit
hokey to me. Can someone suggest how a pro would do it?

   The goal is to take data from 4 columns of a data.frame (data read
in by read.csv) and generate a plot with the borders and text in black
and three lines in different colors. The code below generates that but
loses data because the second and third lines have values greater than
the first which set the Y axis max. I can use something like max(X$d)
to get the max size required but I don't see how to set the Y
dimension it in the first plot command. How do I do that? I looked in
?par but didn't spot it.

   Last, how would I add a legend to explain the 3 lines? I haven't
studied it yet but maybe someone can point me at the right stuff.

   So, how could this little example be made to have all the data on
the plot and how could I code it better? I don't think those
'as.vector' coercions are really the right way.

Thanks,
Mark

X<- data.frame(a=1:10, b=cumsum(X$a), c=cumsum(X$b), d=cumsum(X$c))
X

plot(X$b ~ X$a, type="l", col="blue")
lines(as.vector(X$a),as.vector(X$c), col="green")
lines(as.vector(X$a),as.vector(X$d), col="red")
(Continue reading)

ukoenig | 3 Jul 21:12

Variable names in lattice XY-plot

Hi,
how can I get a more descriptive text
instead of the variable names in my XY-lattice plot,
according to the table below?

Variable    text
acet     = "Acetylaspartate Thalamus"
chol     = "Choline Thalamus"
acetp    = "Acetylaspartate parieoc"
ino      = "Inositole Thalamus"

I could not find a solution.
Please have a look at my syntax.
Thanks a lot,
Udo

library(lattice)

grp <-c(0,1,0,1)
zp <- c(1,1,2,2)
acet <- c(1.7,1.8,1.9,1.8)
chol <- c(0.6, 0.8,0.8, 0.7)
ino <- c(0.6, 0.3, 0.5, 0.4)
acetp <- c(1.8, 1.9, 2.0, 1.8)

data <- data.frame(cbind(grp, zp, acet, chol, ino, acetp))
data$grp <- factor(data$grp)
levels(data$grp) <- c("low","high")

xyplot(acet+chol+ino+acetp ~ zp,
(Continue reading)

Veerappa Chetty | 3 Jul 19:33

exporting interactive rggobi plots

Hi , I have created a parallel coordinate plot using rrgobi. I like to make
a powerpoint slide. I am not able to copy and paste. Is there any way to do
this? Thanks for any help.
Chetty
--

-- 
Professor of Family Medicine
Boston University
Tel: 617-414-6221, Fax:617-414-3345
emails: chettyvk <at> gmail.com,vchetty <at> bu.edu

	[[alternative HTML version deleted]]

bruno Piguet | 3 Jul 19:21

A fast version of ccf () accepting missing values ?

Dear R-Helpers,

   I need to compute cross-correlation on two signals wich may contain
missing values.
   One cannot pass "Na.action=na.pass" to the ccf() function.

  So, I wrote a naive function of my own (see below).
  Unsurprisingly, this function is not very fast.
  Do you think that it is possible to do better, or should I accept my fate
?

Bruno.

my_ccf <- function (X, Y, lag.before = NULL, lag.after = NULL) {
  l_X <- length(X)
  l_Y <- length(Y)

  if  (l_Y != l_X) {
    cat ("X and Y should have same size !")
    return
  }
  if (is.null(lag.before)) {
    lag.before <- l_X / 10
    #should do 10*log10(N/m)
  }
  if (is.null(lag.after)) {
    lag.after <- l_X / 10
    # idem lag.before.
  }

(Continue reading)

Alessandro Bigi | 3 Jul 19:21
Favicon

windrose (circular package) odd table and windrose plot

> R.version
               _                           
platform       i486-pc-linux-gnu           
arch           i486                        
os             linux-gnu                   
system         i486, linux-gnu             
status                                     
major          2                           
minor          8.1                         
year           2008                        
month          12                          
day            22                          
svn rev        47281                       
language       R                           
version.string R version 2.8.1 (2008-12-22)

> packageDescription('circular',fields='Version')
[1] "0.3-8"

Computing a table and plotting a windrose with windrose I have odd (to me) results:

in the table data referred to some wind direction are missing
the frequency plotted in the windrose are different from those indicated in the table
some wind magnitudes are missing in the table

wdir <- rep(seq(0,135,45),10) # 4 directions 0,45,90,135 degrees
wmag <- rep(c(10,5,2,1),10) # constant mag for each direction: 10,5,2,1
t <- windrose(circular(wdir,units='degrees',template='geographics'),wmag,increment=1)

> t$table
(Continue reading)

Mark Knecht | 3 Jul 19:21

What command lists everything in a package?

Hi,
   Two easy questions I'm sure.

1) As an example if I use the code

require(zoo)

then once it's loaded is there a command that lists everything that
zoo provides so that I can study the package?

   Certainly help(zoo) gives me some clues about what zoo does but I'd
like a list. Maybe there's a way to query something but in Rgui under
Win Vista ls() returns nothing after zoo is loaded.

2) Related to the above, how do I tell what packages are currently
loaded at any given time so that I don't waste time loading things
that are already loaded? search() tells me what's available, but
what's loaded? The best I can find so far goes like this:

> a<-.packages(all.available = FALSE)
> a
[1] "zoo"       "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "methods"   "base"
>

Maybe that's as good as it gets in code and if I want better then I
write a function?

Thanks,
Mark
(Continue reading)

Martin Eklund | 3 Jul 18:59
Favicon

Two questions about the cloud function in the lattice package

Hi,

I have two questions regarding the cloud function in the lattice  
package:

1) Is there a way to not print the surrounding frame (i.e. the square  
surrounding the entire plot)?

2) Is there a way to italicize the text displayed with the key argument?

Some sample code:

data(iris)
cloud(Sepal.Length~Petal.Length*Petal.Width,data=iris,
groups=Species,screen=list(z=20,x=-70), col=c("red","blue","green"),  
pch=c(20,20,20),
perspective=FALSE,
key=list(title="IrisData",x=.05,y=.95,corner=c(0,1),
border=TRUE,
points=list(alpha=c(1,1,1), cex=c(0.8,0.8,0.8),  
col=c("red","blue","green"), fill=c("#CCFFFF","#FFCCFF","#CCFFCC"),  
font=c(1,1,1), pch=c(20,20,20)),
text=list(c("setosa","versicolor","virginica"))))

Neither setting border=F nor changing font=c(1,1,1) to font=c(3,3,3)  
seem to do anything (as far as I can tell), which was how I thought  
that I could remove the framing border and italicize the text in the  
figure legend.

Does anyone have any pointers as to how to achieve what I would like  
(Continue reading)


Gmane