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

2013-07-26 Thread Pascal Oettli

Hello,

Once again, the matrix EWMA has not the correct size.

Did you carefully read the answer by Thomas Stewart?
https://stat.ethz.ch/pipermail/r-help/attachments/20130724/c454b0f7/attachment.pl

Extract of his reply: When you expand the example to 5 stocks,
there will be 15 elements (5 variances and 10 covariances)

 EWMA-matrix(nrow=T,ncol=15))

Regards,
Pascal

On 26/07/2013 14:37, G Girija wrote:

Hi All,

I have 5 stock values and i am calculating EWMA
followed the logic as given ind following link.[
http://www.orecastingfinancialrisk.com/3.htmlhttp://www.forecastingfinancialrisk.com/3.html
]

library('tseries')
returns[,1]-returns[,1]-mean(returns[,1])
returns[,2]-returns[,2]-mean(returns[,2])
returns[,3]-returns[,3]-mean(returns[,3])
returns[,4]-returns[,4]-mean(returns[,4])
returns[,5]-returns[,5]-mean(returns[,5])
T-length(returns[,1])
T
EWMA-matrix(nrow=T,ncol=5)
lambda=0.94
S-cov(returns)
S
EWMA[1,] - S[lower.tri(S,diag=TRUE)]


*Error in EWMA[1, ] - S[lower.tri(S, diag = TRUE)] : *
*  number of items to replace is not a multiple of replacement length*
*
*
for(i in 2:T)
{
   S- lambda*S +(1-lambda)*t(returns[i])%*% returns[i]
EWMA[i,] - S[lower.tri(S,diag=TRUE)]
}
*
*

[[alternative HTML version deleted]]

__
R-help@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.



__
R-help@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.


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

2013-07-25 Thread G Girija
Hi All,

I have 5 stock values and i am calculating EWMA
followed the logic as given ind following link.[
http://www.orecastingfinancialrisk.com/3.htmlhttp://www.forecastingfinancialrisk.com/3.html
]

library('tseries')
returns[,1]-returns[,1]-mean(returns[,1])
returns[,2]-returns[,2]-mean(returns[,2])
returns[,3]-returns[,3]-mean(returns[,3])
returns[,4]-returns[,4]-mean(returns[,4])
returns[,5]-returns[,5]-mean(returns[,5])
T-length(returns[,1])
T
EWMA-matrix(nrow=T,ncol=5)
lambda=0.94
S-cov(returns)
S
EWMA[1,] - S[lower.tri(S,diag=TRUE)]


*Error in EWMA[1, ] - S[lower.tri(S, diag = TRUE)] : *
*  number of items to replace is not a multiple of replacement length*
*
*
for(i in 2:T)
{
  S- lambda*S +(1-lambda)*t(returns[i])%*% returns[i]
EWMA[i,] - S[lower.tri(S,diag=TRUE)]
}
*
*

[[alternative HTML version deleted]]

__
R-help@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.


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

2012-06-29 Thread ascotilla
Hello,

I'm a complete newbie to R so sorry if this is too basic..:-S

I have to modify some scripts someone else did to make it work with my data.
For some reason, one of the scripts which were supposed to work is not, and
I get the error message number of items to replace is not a multiple of
replacement length.

The script is this one:

*open_lpj_nc_gpp - function(file_name,varname,y1850_file_no,
recentre,startyr,nyrs)
  {
library(ncdf)

start_yr=y1850_file_no+(startyr-1850)

print()
filename=paste(file_name,start_yr,.nc,sep=)
print(Opening:)
print(varname)
print(in:)
print(filename)
ncfile=open.ncdf(filename)
mod1=get.var.ncdf(ncfile,varname)
print()

a=dim(mod1)
print(a)
b=length(a)

if (b==3) {
  mod =array(0,dim=c(a[1],a[2],a[3],nyrs))
  modi=array(0,dim=a)
} else {
  mod =array(0,dim=c(a[1],a[2],1,nyrs))
  modi=array(0,dim=c(a[1],a[2],1))
  a[3]=1
}
if (recentre) {
yay=mod[1:(a[1]/2),,,1]
wow=mod1[(1+a[1]/2):a[1],,,]
mod[1:(a[1]/2),,,1]=mod1[(1+a[1]/2):a[1],,,]
mod[(1+a[1]/2):a[1],,,1]=mod1[1:(a[1]/2),,]
  } else {
mod[,,,1]=mod1
  }
remove(mod1)

p=1
while (pnyrs) {
  y=p+start_yr
  p=p+1  
  remove(filename)
  filename=paste(file_name,y,quot;.ncquot;,sep=quot;quot;)
  
  print(quot;Opening:quot;)
  print(varname)
  print(quot;in:quot;)
  print(filename)
  print(quot;quot;)
  
  ncfile=open.ncdf(filename)
  modi[,,]=get.var.ncdf(ncfile,varname)
  if (recentre) {
mod[1:(a[1]/2),,,p]=modi[(1+a[1]/2):a[1],,]
mod[(1+a[1]/2):a[1],,,p]=modi[1:(a[1]/2),,]
  } else {
mod[,,,p]=modi
  }
}

for (i in 1:a[1]) {
  for (j in 1:a[2]) {
for (k in 1:a[3]) {
  for (l in 1:p){
if (is.na(mod[i,j,k,l])==0) {
  if (mod[i,j,k,l]1E9) {
mod[i,j,k,l]=NaN
  }
}
  }
}
  }
}
   
print()
return(mod)

  }
*

And this is the error I get:

*Error in mod[1:(a[1]/2), , , 1] = mod1[(1 + a[1]/2):a[1], , , ] : 
  number of items to replace is not a multiple of replacement length*

The dimensions of the mod1 file are [720 360 9 12]. I've tried to modify the
number of commas, and it worked to sort out a dimensions problem I had
before. However, I'm not really sure about what this error mean. I guess it
has to do with the fact that the mod defined has different dimensions (720
360 1 8), but I presume that was made in purpose...:-S

Any help will be really appreciated, I have this incompatibilities in
several scripts and I don't know if they come from the script itself or from
any problem with the inputs (which would be really annoying...)

Thank you in advance!

Cheers


--
View this message in context: 
http://r.789695.n4.nabble.com/number-of-items-to-replace-is-not-a-multiple-of-replacement-length-tp4634864.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


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 of x with
something.
We then give it a vector of length two as that something.
   x[1:5] - 1:2 It doesn't work, because 5 is not a multiple of 2.

In contrast
   x[1:4] - 1:2succeeds. Whether or not it does what was intended is
another question.

 x - 1:6
 x
[1] 1 2 3 4 5 6
 x[1:4] - 1:2
 x
[1] 1 2 1 2 5 6

Modifying the number of commas is unlikely to be the solution.

It's also going to be very difficult to solve your problem remotely,
because of not having the input data for one thing, also having no
understanding of what the script is intended to do.

Best guess is that your input data has different dimensions. Not how many
dimensions, but the size of the dimensions.

Couple of things you can do.

Immediately after the error, type
   traceback()
This might give a clue. Or, you can type


   debug(open_lpj_nc_gpp)before running the function. You can then step
through the function and check the values of variables as you go.

-Don


  

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/29/12 4:25 AM, ascotilla mmartin...@gmail.com wrote:

Hello,

I'm a complete newbie to R so sorry if this is too basic..:-S

I have to modify some scripts someone else did to make it work with my
data.
For some reason, one of the scripts which were supposed to work is not,
and
I get the error message number of items to replace is not a multiple of
replacement length.

The script is this one:

*open_lpj_nc_gpp - function(file_name,varname,y1850_file_no,
recentre,startyr,nyrs)
  {
library(ncdf)

start_yr=y1850_file_no+(startyr-1850)

print()
filename=paste(file_name,start_yr,.nc,sep=)
print(Opening:)
print(varname)
print(in:)
print(filename)
ncfile=open.ncdf(filename)
mod1=get.var.ncdf(ncfile,varname)
print()

a=dim(mod1)
print(a)
b=length(a)

if (b==3) {
  mod =array(0,dim=c(a[1],a[2],a[3],nyrs))
  modi=array(0,dim=a)
} else {
  mod =array(0,dim=c(a[1],a[2],1,nyrs))
  modi=array(0,dim=c(a[1],a[2],1))
  a[3]=1
}
if (recentre) {
yay=mod[1:(a[1]/2),,,1]
wow=mod1[(1+a[1]/2):a[1],,,]
mod[1:(a[1]/2),,,1]=mod1[(1+a[1]/2):a[1],,,]
mod[(1+a[1]/2):a[1],,,1]=mod1[1:(a[1]/2),,]
  } else {
mod[,,,1]=mod1
  }
remove(mod1)

p=1
while (pnyrs) {
  y=p+start_yr
  p=p+1  
  remove(filename)
  filename=paste(file_name,y,quot;.ncquot;,sep=quot;quot;)
  
  print(quot;Opening:quot;)
  print(varname)
  print(quot;in:quot;)
  print(filename)
  print(quot;quot;)
  
  ncfile=open.ncdf(filename)
  modi[,,]=get.var.ncdf(ncfile,varname)
  if (recentre) {
mod[1:(a[1]/2),,,p]=modi[(1+a[1]/2):a[1],,]
mod[(1+a[1]/2):a[1],,,p]=modi[1:(a[1]/2),,]
  } else {
mod[,,,p]=modi
  }
}

for (i in 1:a[1]) {
  for (j in 1:a[2]) {
for (k in 1:a[3]) {
  for (l in 1:p){
if (is.na(mod[i,j,k,l])==0) {
  if (mod[i,j,k,l]1E9) {
mod[i,j,k,l]=NaN
  }
}
  }
}
  }
}
   
print()
return(mod)

  }
*

And this is the error I get:

*Error in mod[1:(a[1]/2), , , 1] = mod1[(1 + a[1]/2):a[1], , , ] :
  number of items to replace is not a multiple of replacement length*

The dimensions of the mod1 file are [720 360 9 12]. I've tried to modify
the
number of commas, and it worked to sort out a dimensions problem I had
before. However, I'm not really sure about what this error mean. I guess
it
has to do with the fact that the mod defined has different dimensions (720
360 1 8), but I presume that was made in purpose...:-S

Any help will be really appreciated, I have this incompatibilities in
several scripts and I don't know if they come from the script itself or
from
any problem with the inputs (which would be really annoying...)

Thank you in advance!

Cheers


--
View this message in context:
http://r.789695.n4.nabble.com/number-of-items-to-replace-is-not-a-multiple
-of-replacement-length-tp4634864.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.

__
R-help@r-project.org 

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

2012-06-29 Thread ascotilla
Thanks a lot, I thought I was moving forward because I got a different error,
but it seems that I didn't move forward at all..:-S...It was quite basic,
right...?

That was very helpful, I'll try to sort out the dimensions problem now on my
own...I want to fight a bit with it to see if I'm able to sort that out
alone without embarrasing myself again..;-)

Cheers

--
View this message in context: 
http://r.789695.n4.nabble.com/number-of-items-to-replace-is-not-a-multiple-of-replacement-length-tp4634864p4634902.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


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

2011-11-18 Thread Gyanendra Pokharel
Hi all, following is my R -code and shows the error given below
 n - 100
 k-2
 x1 -c(1, 3);x2 - c(2,5)
 X - matrix(c(0,0), nrow = 2, ncol = n)
 for(i in 1:k)
+ X[i, ] - mh1.epidemic(n,x1[i],x2[i])
Error in X[i, ] - mh1.epidemic(n,x1[i],x2[i]): 
  number of items to replace is not a multiple of replacement length
 
 psi -t(apply(X, c(1,2), cumsum))
 for(i in 1:nrow(psi)){
+ psi[i,] psi[i,]/(1:ncol(psi))
+ print(Gelman.Rubin(psi))
+ 
+ }
Can some one suggest me what this error means and how could I fix it?
[[alternative HTML version deleted]]

__
R-help@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.


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

2011-11-18 Thread Milan Bouchet-Valat
Le vendredi 18 novembre 2011 à 04:45 -0800, Gyanendra Pokharel a écrit :
 Hi all, following is my R -code and shows the error given below
  n - 100
  k-2
  x1 -c(1, 3);x2 - c(2,5)
  X - matrix(c(0,0), nrow = 2, ncol = n)
  for(i in 1:k)
 + X[i, ] - mh1.epidemic(n,x1[i],x2[i])
 Error in X[i, ] - mh1.epidemic(n,x1[i],x2[i]): 
  number of items to replace is not a multiple of replacement length
 
  psi -t(apply(X, c(1,2), cumsum))
  for(i in 1:nrow(psi)){
 + psi[i,] psi[i,]/(1:ncol(psi))
 + print(Gelman.Rubin(psi))
 + 
 + }
 Can some one suggest me what this error means and how could I fix it?
The message is relatively clear. ;-)

It means the number of elements in the mh1.epidemic(n,x1[i],x2[i])
vector isn't a multiple of the number of elements in X[i, ]. In the
standard case, you want these two vectors to be of the same length, and
there are too many or too few elements in mh1.epidemic(n,x1[i],x2[i]).

You can check that with by looking at:
length(mh1.epidemic(n,x1[i],x2[i]))
and
length(X[i, ])


Cheers

__
R-help@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.


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

2011-09-28 Thread dunner
Please help with this error message 

drugbook is an 885 x 32 dataframe

 names(drugbook)

[1] DRUG1  DRUG2  DRUG3  DRUG4  DRUG5 
 [6] DRUG6  DRUG7  DRUG8  DRUG9  DRUG10
[11] DRUG11 DRUG12 DRUG13 DRUG14 DRUG15
[16] DRUG16 DrugDose1  DrugDose2  DrugDose3  DrugDose4 
[21] DrugDose5  DrugDose6  DrugDose7  DrugDose8  DrugDose9 
[26] DrugDose10 DrugDose11 DrugDose12 DrugDose13 DrugDose14
[31] DrugDose15 DrugDose16

Equivs is a dataframe holding information for a certain subclass of drugs

 head(Equivs)
  Name  Equiv
1   Alprazolam   0.5
2   Bromazepam   5.5
3 Chlordiazepoxide  25.0
4 Clobazam  20.0
5   Clonazepam   0.5
6  Clorazepate  15.0

What I'm trying to is for each element of drugbook, get the value in
Equivs$Equiv, and multiply it by the corresponding drug dose, which will be
in the n+16 th  column on in the same row of drugbook.

Not all of the grabbed names from Drugbook will be in the dataframe Equivs,
though. So sometimes the == will return a null.

i.e. DrugDose16 is the dose of Drug 16

this I think should work: ( I did try apply and got knotted, so stopped)

mydosequivalents=list()
for( c in 1:16) {
  for (r in 1:885){
name-as.character(drugbook[r,c]);
equivalent-Equivs$Equiv[Equivs$Name==name];
dosequivalent-drugbook[r,c+16] * equivalent;
if (length(dosequivalent)0) mydosequivalents[r][c]-dosequivalent
else (mydosequivalents[r][c]-0)
  }
}

But it is throwing an error, and I can't figure out why. I remedied a
previous error by checking the length of the equivalent.

warnings() 
50: In mydosequivalents[c][r] - dosequivalent :
  number of items to replace is not a multiple of replacement length

mydosequivalents ends up being full of NULL and zeros


Thanks in advance for any help

Ross

--
View this message in context: 
http://r.789695.n4.nabble.com/number-of-items-to-replace-is-not-a-multiple-of-replacement-length-tp3851265p3851265.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


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

2011-09-28 Thread Jean V Adams
dunner wrote on 09/28/2011 08:43:32 AM:
 
 Please help with this error message 
 
 drugbook is an 885 x 32 dataframe
 
  names(drugbook)
 
 [1] DRUG1  DRUG2  DRUG3  DRUG4  DRUG5 
  [6] DRUG6  DRUG7  DRUG8  DRUG9  DRUG10 
 [11] DRUG11 DRUG12 DRUG13 DRUG14 DRUG15 
 [16] DRUG16 DrugDose1  DrugDose2  DrugDose3  DrugDose4 
 [21] DrugDose5  DrugDose6  DrugDose7  DrugDose8  DrugDose9 
 [26] DrugDose10 DrugDose11 DrugDose12 DrugDose13 DrugDose14
 [31] DrugDose15 DrugDose16
 
 Equivs is a dataframe holding information for a certain subclass of 
drugs
 
  head(Equivs)
   Name  Equiv
 1   Alprazolam   0.5
 2   Bromazepam   5.5
 3 Chlordiazepoxide  25.0
 4 Clobazam  20.0
 5   Clonazepam   0.5
 6  Clorazepate  15.0
 
 What I'm trying to is for each element of drugbook, get the value in
 Equivs$Equiv, and multiply it by the corresponding drug dose, which will 
be
 in the n+16 th  column on in the same row of drugbook.
 
 Not all of the grabbed names from Drugbook will be in the dataframe 
Equivs,
 though. So sometimes the == will return a null.
 
 i.e. DrugDose16 is the dose of Drug 16
 
 this I think should work: ( I did try apply and got knotted, so stopped)
 
 mydosequivalents=list()
 for( c in 1:16) {
   for (r in 1:885){
 name-as.character(drugbook[r,c]);
 equivalent-Equivs$Equiv[Equivs$Name==name];
 dosequivalent-drugbook[r,c+16] * equivalent;
 if (length(dosequivalent)0) mydosequivalents[r][c]-dosequivalent
 else (mydosequivalents[r][c]-0)
   }
 }
 
 But it is throwing an error, and I can't figure out why. I remedied a
 previous error by checking the length of the equivalent.


I think your error is coming from the way that you are trying to populate 
the list using [r][c].  Are you trying to have mydosequivalents be a list 
of r vectors each with c elements?


 warnings() 
 50: In mydosequivalents[c][r] - dosequivalent :
   number of items to replace is not a multiple of replacement length
 
 mydosequivalents ends up being full of NULL and zeros
 
 
 Thanks in advance for any help
 
 Ross


Another way:

# using my example data
drugbook - data.frame(DRUG1=letters[1:5], DRUG2=letters[6:10], 
DrugDose1=1:5, DrugDose2=6:10)
Equivs - data.frame(Name=letters[-c(2, 8)], Equiv=100*(1:24))

mydosequivalents - apply(drugbook[, 1:2], 2, 
function(x) Equivs$Equiv[match(x, Equivs$Name)])*drugbook[, 3:4]
mydosequivalents[is.na(mydosequivalents)] - 0


# this should work for your real data
mydosequivalents - apply(drugbook[, 1:16], 2, 
function(x) Equivs$Equiv[match(x, Equivs$Name)])*drugbook[, 17:32]
mydosequivalents[is.na(mydosequivalents)] - 0

Jean
[[alternative HTML version deleted]]

__
R-help@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.


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

2010-11-01 Thread Mipam Bruining
Hey all,

I am writing a function in which I will have a matrix of 4 columns and a
variable amount of rows.
The first to columns will always contain be of the Character type, the third
and fourth columns
can be a variation of data types, usually characters and integers, but
sometimes lists or matrices.

At one point the code makes, for each row, a copy of that row, then it makes
some adjustments
to the values in the third column, and then it overwrites the original
matrix row with the copy. It is here
that I get the error from my subject title, number of items to replace is
not a multiple of replacement length.
This is strange because the items to replace in this instance seem to me and
should be an exact copy of the
replacement, save that the number 0 in this particular instance is to be
replaced with the number 58.

If I print the variables in question I get this: (added some tabs to allign
the columns for readability)

print(parameterList[aCounter, 3])
[[1]]
  [,1]
 [,2]   [,3][,4]
exampleSingleSelect   Insert single selection box title here
SingleSelect  1List,3
exampleSlider Insert slider bar title here
Slider0   List,2

print(blaah)
 [,1]
 [,2]   [,3]   [,4]
exampleSingleSelect  Insert single selection box title here SingleSelect
1List,3
exampleSliderInsert slider bar title here
 Slider   58   List,2


The command that caused the error is this:

parameterList[aCounter, 3] - blaah


I hope I've given enough information for someone else to be able to make
sense of it all. If not I'd be happy to supply additional code
or info on how the script works, but I think that most of it would be
irrelevant and complicated.

 Many thanks in advance,
Mipam Bruining

[[alternative HTML version deleted]]

__
R-help@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.


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

2010-11-01 Thread Ivan Calandra

Hi,

I think you _*should*_ provide more:
- the objects you have, such as parameterList and blaah: copy the output 
from dput(object) in your next e-mail

- the _*relevant*_ code for how you've built them

I guess you will get more and better answers if you give a clear and 
complete description of your problem.


Ivan

Le 11/1/2010 12:55, Mipam Bruining a écrit :

Hey all,

I am writing a function in which I will have a matrix of 4 columns and a
variable amount of rows.
The first to columns will always contain be of the Character type, the third
and fourth columns
can be a variation of data types, usually characters and integers, but
sometimes lists or matrices.

At one point the code makes, for each row, a copy of that row, then it makes
some adjustments
to the values in the third column, and then it overwrites the original
matrix row with the copy. It is here
that I get the error from my subject title, number of items to replace is
not a multiple of replacement length.
This is strange because the items to replace in this instance seem to me and
should be an exact copy of the
replacement, save that the number 0 in this particular instance is to be
replaced with the number 58.

If I print the variables in question I get this: (added some tabs to allign
the columns for readability)


print(parameterList[aCounter, 3])

[[1]]
   [,1]
  [,2]   [,3][,4]
exampleSingleSelect   Insert single selection box title here
SingleSelect  1List,3
exampleSlider Insert slider bar title here
Slider0   List,2


print(blaah)

  [,1]
  [,2]   [,3]   [,4]
exampleSingleSelect  Insert single selection box title here SingleSelect
1List,3
exampleSliderInsert slider bar title here
  Slider   58   List,2


The command that caused the error is this:


parameterList[aCounter, 3]- blaah


I hope I've given enough information for someone else to be able to make
sense of it all. If not I'd be happy to supply additional code
or info on how the script works, but I think that most of it would be
irrelevant and complicated.

  Many thanks in advance,
Mipam Bruining

[[alternative HTML version deleted]]

__
R-help@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.



--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Abt. Säugetiere
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php

__
R-help@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.


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

2010-11-01 Thread Mipam Bruining
Hello,

here are the results from using dput() on the objects in question.

dput(blaah)
structure(list(Insert single selection box title here, Insert slider bar
title here,
SingleSelect, Slider, 1, 50, list(Option a, Option b,
Option c), list(0, 100)), .Dim = c(2L, 4L), .Dimnames = list(
c(exampleSingleSelect, exampleSlider), NULL))

dput(parameterList[aCounter, 3])
list(structure(list(Insert single selection box title here,
Insert slider bar title here, SingleSelect, Slider,
1, 0, list(Option a, Option b, Option c), list(0, 100)), .Dim =
c(2L,
4L), .Dimnames = list(c(exampleSingleSelect, exampleSlider
), NULL)))


The matrix parameterList was constructed as followed:

R script
exampleSlider = list(Insert slider bar title here, Slider, 0,
list(0,100))
exampleSingleSelect = list(Insert single selection box title here,
SingleSelect, 1,
list(Option a, Option b, Option c))

parameterList = rbind(list(more advanced options, Button,
rbind(exampleSingleSelect,exampleSlider ),  )
...
aParameterValue - as.matrix(parameterList[[aCounter,3]])
...
blaah - aParameterValue
...
parameterList[aCounter, 3] - blaah

/R script

As a side note: The ... represents various other lines. The
construction parameterList - blaah - aParameterValue is an ad-hoc
solution to using global and local variables that I will try to smooth over
once it works as it is now. To be more specific, the value aParameterValue
is a local variable that is created in a subfunction which is called upon
once for each row in parameterList, each time the user presses a button in
the created tcltk window.
The blaah variable is a global variable that solves the problem of tlctk
buttons not being able to receive the returned values from the function it
calls and parameterList somehow not being able to be updated correctly
within this function.

I hope anyone can make sense of this story :S

Mipam Bruining


2010/11/1 Ivan Calandra ivan.calan...@uni-hamburg.de

 Hi,

 I think you _*should*_ provide more:
 - the objects you have, such as parameterList and blaah: copy the output
 from dput(object) in your next e-mail
 - the _*relevant*_ code for how you've built them

 I guess you will get more and better answers if you give a clear and
 complete description of your problem.

 Ivan

 Le 11/1/2010 12:55, Mipam Bruining a écrit :

 Hey all,

 I am writing a function in which I will have a matrix of 4 columns and a
 variable amount of rows.
 The first to columns will always contain be of the Character type, the
 third
 and fourth columns
 can be a variation of data types, usually characters and integers, but
 sometimes lists or matrices.

 At one point the code makes, for each row, a copy of that row, then it
 makes
 some adjustments
 to the values in the third column, and then it overwrites the original
 matrix row with the copy. It is here
 that I get the error from my subject title, number of items to replace is
 not a multiple of replacement length.
 This is strange because the items to replace in this instance seem to me
 and
 should be an exact copy of the
 replacement, save that the number 0 in this particular instance is to be
 replaced with the number 58.

 If I print the variables in question I get this: (added some tabs to
 allign
 the columns for readability)

  print(parameterList[aCounter, 3])

 [[1]]
   [,1]
  [,2]   [,3][,4]
 exampleSingleSelect   Insert single selection box title here
 SingleSelect  1List,3
 exampleSlider Insert slider bar title here
 Slider0   List,2

  print(blaah)

  [,1]
  [,2]   [,3]   [,4]
 exampleSingleSelect  Insert single selection box title here
 SingleSelect
 1List,3
 exampleSliderInsert slider bar title here
  Slider   58   List,2


 The command that caused the error is this:

  parameterList[aCounter, 3]- blaah


 I hope I've given enough information for someone else to be able to make
 sense of it all. If not I'd be happy to supply additional code
 or info on how the script works, but I think that most of it would be
 irrelevant and complicated.

  Many thanks in advance,
 Mipam Bruining

[[alternative HTML version deleted]]

 __
 R-help@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.


 --
 Ivan CALANDRA
 PhD Student
 University of Hamburg
 Biozentrum Grindel und Zoologisches Museum
 Abt. Säugetiere
 Martin-Luther-King-Platz 3
 D-20146 Hamburg, GERMANY
 +49(0)40 42838 6231
 ivan.calan...@uni-hamburg.de

 **
 http://www.for771.uni-bonn.de
 http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php

 __
 R-help@r-project.org mailing list
 

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

2010-11-01 Thread Mipam Bruining
Hello,

I just wanted to say that I just stumbled upon the solution by accident!
After your comment on lists I searched for some more information on vectors,
lists and matrices. I read that using double ['s instead of singles drops
the names of the dimensions used.
I then gave
parameterList[aCounter, 3] - blaah
instead of
parameterList[[aCounter, 3]] - blaah
a quick try and voila!

In hindsight I guess I was just thinking to much in python style where
matrices dont have dimension naming. (python being the language in which I
first learned to program and quite similar to R)

But thanks for your help anyway!

Mipam Bruining

2010/11/1 Ivan Calandra ivan.calan...@uni-hamburg.de

 Hi,

 Not sure what the problem is, but you have weird data structures. I mean,
 having lists within matrices is possible (I've learned it last week!), but
 it is really confusing.

 You didn't provide every object like the complete parameterList and
 aCounter, but the only difference I see in

 aParameterValue - as.matrix(parameterList[[aCounter,3]])
 ...
 blaah - aParameterValue
 ...
 parameterList[aCounter, 3] - blaah
 between the original parameterList[[aCounter,3]] and the new one is that
 your aParameterValue, and therefore blaah, is a matrix, and a weird one,
 that you try to assign into a non-matrix object.

 Have you tried without as.matrix()? What about storing everything in a list
 and using indexing?

 HTH,
 Ivan


 Le 11/1/2010 14:43, Mipam Bruining a écrit :

 Hello,

 here are the results from using dput() on the objects in question.

 dput(blaah)
 structure(list(Insert single selection box title here, Insert slider
 bar title here,
SingleSelect, Slider, 1, 50, list(Option a, Option b,
Option c), list(0, 100)), .Dim = c(2L, 4L), .Dimnames = list(
c(exampleSingleSelect, exampleSlider), NULL))

 dput(parameterList[aCounter, 3])
 list(structure(list(Insert single selection box title here,
Insert slider bar title here, SingleSelect, Slider,
1, 0, list(Option a, Option b, Option c), list(0, 100)), .Dim =
 c(2L,
 4L), .Dimnames = list(c(exampleSingleSelect, exampleSlider
 ), NULL)))


 The matrix parameterList was constructed as followed:

 R script
 exampleSlider = list(Insert slider bar title here, Slider, 0,
 list(0,100))
 exampleSingleSelect = list(Insert single selection box title here,
 SingleSelect, 1,
 list(Option a, Option b, Option c))

 parameterList = rbind(list(more advanced options, Button,
 rbind(exampleSingleSelect,exampleSlider ),  )
 ...
 aParameterValue - as.matrix(parameterList[[aCounter,3]])
 ...
 blaah - aParameterValue
 ...
 parameterList[aCounter, 3] - blaah

 /R script

 As a side note: The ... represents various other lines. The construction
 parameterList - blaah - aParameterValue is an ad-hoc solution to using
 global and local variables that I will try to smooth over once it works as
 it is now. To be more specific, the value aParameterValue is a local
 variable that is created in a subfunction which is called upon once for each
 row in parameterList, each time the user presses a button in the created
 tcltk window.
 The blaah variable is a global variable that solves the problem of tlctk
 buttons not being able to receive the returned values from the function it
 calls and parameterList somehow not being able to be updated correctly
 within this function.

 I hope anyone can make sense of this story :S

 Mipam Bruining


 2010/11/1 Ivan Calandra ivan.calan...@uni-hamburg.de mailto:
 ivan.calan...@uni-hamburg.de


Hi,

I think you _*should*_ provide more:
- the objects you have, such as parameterList and blaah: copy the
output from dput(object) in your next e-mail
- the _*relevant*_ code for how you've built them

I guess you will get more and better answers if you give a clear
and complete description of your problem.

Ivan

Le 11/1/2010 12:55, Mipam Bruining a écrit :

Hey all,

I am writing a function in which I will have a matrix of 4
columns and a
variable amount of rows.
The first to columns will always contain be of the Character
type, the third
and fourth columns
can be a variation of data types, usually characters and
integers, but
sometimes lists or matrices.

At one point the code makes, for each row, a copy of that row,
then it makes
some adjustments
to the values in the third column, and then it overwrites the
original
matrix row with the copy. It is here
that I get the error from my subject title, number of items
to replace is
not a multiple of replacement length.
This is strange because the items to replace in this instance
seem to me and
should be an exact copy of the
replacement, save that the number 0 in this particular
instance is to be
replaced with the number 58.

If I print the variables in question I get this: 

[R] bootstrapping error message Error in t.star[r, ] - statistic(data, i[r, ], ...) : number of items to replace is not a multiple of replacement length

2009-07-08 Thread Karina Boege



Hi,

I am trying to run some bootstraps with the boot package. When I run 
it with 400 replicates it does it ok, but then I need to run the same 
analysis but with 89, 86, 102 and 106 samples (for four different 
environments), and then is when I get the error message:


 mybootstrap - boot(Datos, mystat, 2000)
Error in t.star[r, ] - statistic(data, i[r, ], ...) :  number of 
items to replace is not a multiple of replacement length


Anyone familiar with this error message?
Does anyone knows the minimum sample size for boot package to run 
properly? Is there anyway to tell R how many samples should it pick 
for the resampling?


If it helps, this is how my model looks like:

mymodel = lm(Datos[,4]~Datos[,1]+ 
Datos[,8]+Datos[,9]+Datos[,10]+Datos[,11]+Datos[,12])

summary(mymodel)

mystat - function(a,b)
f- lm(a[b,4]~a[b,1]+a[b,8]+ a[b,9]+a[b,10]+a[b,11]+a[b,12])$coef

mybootstrap - boot(Datos, mystat, 2000)

INT1-boot.ci(mybootstrap, conf=0.95, type=all, index=1)
INT2-boot.ci(mybootstrap, conf=0.95, type=all, index=2)
INT3-boot.ci(mybootstrap, conf=0.95, type=all, index=3)
INT4-boot.ci(mybootstrap, conf=0.95, type=all, index=4)
INT5-boot.ci(mybootstrap, conf=0.95, type=all, index=5)
INT6-boot.ci(mybootstrap, conf=0.95, type=all, index=6)
INT7-boot.ci(mybootstrap, conf=0.95, type=all, index=7)


Thanks for your help! I am new to bootstraps and to R, and I feel 
pretty lonely with this


Karina Boege

__
R-help@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.