[R] Error: "subscript out of bounds"

2008-12-01 Thread Alex99

Hi All,

I am trying to replace the "NA" values in a matrix by using the following
function:
it gets a "name" of the matrix or list or vector and turns it to a matrix
called "m". 
then checks the elements of the matrix and if any of them is "NA" replace
them with "0".

rep=function(name){
m=as.matrix(name)
for(i in 1:length(m)){
 for(j in 1:length(m)){
  if(is.na(m[i,j])){
m[i,j]=0 


when I use the function with the following matrix:

  X1  X2  X3X5
X1  1.00 NA NA -0.25
X2NA  1 NANA
X3NA NA  1NA
X5 -0.25 NA NA  1.00

I get this error: "subscript out of bounds".
I used debug on "rep" function and it seems it works for i=1 and j=1&2&3&4&5
after that, when it's suppose to go to i=2 I get the error.
any idea why and how to fix it?
Thanks
-- 
View this message in context: 
http://www.nabble.com/Error%3A-%22subscript-out-of-bounds%22-tp20773650p20773650.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: "mean" and "replicate"

2008-11-28 Thread Alex99

Hi all,

I used the "replicate" function to make 2 samples from file "test" with 5
records in each sample and saved the output in "result".

result=replicate(2,test[,sample(colnames(test),5,replace
=FALSE)],simplify=FALSE)


now I need to calculate the mean of each cell; i.e. I need to add "the
number in cell 1&1 from sample 1" and "the number in cell 1&1 in sample 2"
and divide it by 2. and do the same for all numbers in two sample( adding   
the number in cell 1&2 from sample 1" and "the number in cell 1&2 in sample
2",...)

does anyone have any idea how to do it?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Help%3A-%22mean%22-and-%22replicate%22-tp20737544p20737544.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] Transpose and replicate

2008-11-28 Thread Alex99


Hi all,
I used the "replicate" function to make 2 samples from file test with 5
records in each sample and saved the output in "result".

result=replicate(2,test[,sample(colnames(test),5,replace =
FALSE)],simplify=FALSE)

now I need to transpose each sample, but when I use:

t(result) 

or  

result=t(replicate(2,test[,sample(colnames(test),5,replace =
FALSE)],simplify=FALSE))

I get this:

[,1] [,2]   [,3][,4] [,5]   
[1,] Integer,300 Integer,300 Integer,300 Integer,300 Integer,300

anyone has any idea how can I fix it?
Thanks


-- 
View this message in context: 
http://www.nabble.com/Transpose-and-replicate-tp20735722p20735722.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 with "replicate"

2008-11-27 Thread Alex99


Hello everyone,
I have a file called "trans" which has 100 records (rows) and 60 columns.
I need to make 2 samples (with 5 records in each) out of this file with no
replacement, so I used "replicate".
The sampling part works fine and I called the outcome "result".

my problem is then I need to calculate the correlation matrix for each
sample. I used "do.call" and called the outcome "CORE". but the problem is
when I get my out put it's not separated for each sample. they are all
together and I need them to be separated. just to give U an idea I copy and
paste the out put:

  616783805134   
217
616  1. -0.08522865 -0.15018785 -0.12462239 -0.04279605
783 -0.08522865  1. -0.02986738 -0.04731350  0.33191790
805 -0.15018785 -0.02986738  1.  0.15483873 -0.08998425
134 -0.12462239 -0.04731350  0.15483873  1.  0.16290948
217 -0.04279605  0.33191790 -0.08998425  0.16290948  1.
607  1. -0.12662932  0.16116459 -0.03479445 -0.03479445   *(from
here is for the 2nd sample)
604 -0.12662932  1.  0.01298701 -0.06168397 -0.06168397
698  0.16116459  0.01298701  1. -0.03925343 -0.03925343
639 -0.03479445 -0.06168397 -0.03925343  1. -0.01694915
989 -0.03479445 -0.06168397 -0.03925343 -0.01694915  1.
  
does any one has any idea how can I separate the result for 2 samples? 

This is my code:
result=replicate(2,trans[,sample(colnames(trans),5,replace =
FALSE)],simplify=FALSE)
CORE=do.call(rbind,lapply(result,function(x) cor(x)))

-- 
View this message in context: 
http://www.nabble.com/Help-with-%22replicate%22-tp20722891p20722891.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 With Graphs

2008-11-07 Thread Alex99

Hi guys,

I am truing to draw a circle and choose 10 points on the circle and put a
number from 1 to 10 above each point. I don't have a problem with drawing a
circle and choosing 10 points. my problem is with numbering . is it even
possible to put a number above each chosen point? if so any idea how to do
it?

ps: the circle has red dots and the selected points are in black.

here is my code:

D=cos(2*pi*(0:9)/10)
C=sin(2*pi*(0:9)/10)

x1=(sin((0:100)*2*pi/100))
y1=(cos((0:100)*2*pi/100))
plot(x1,y1,col="red")

points(C,D)

Thanks,
-- 
View this message in context: 
http://www.nabble.com/Help-With-Graphs-tp20385465p20385465.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 with Plots

2008-10-29 Thread Alex99

Hi there,
I am trying to have a connectivity graph (two plots at once) in R: 
this is an example:

x1=sin((0:100)*2*pi/100)
y1=cos((0:100)*2*pi/100)
 plot(x1,y1)

will draw a circle and

x2=c(1,9,3,4,8,4,2,0)
y2=c(3,6,8,2,4,1,9,6)
plot(x2,y2,type="b")

will draw a graph with corresponding x's and y's and connects the point.

I want to have a circle with these points connected to each other inside the
circle. is it possible to do it in R?

Thanks 
-- 
View this message in context: 
http://www.nabble.com/Help-with-Plots-tp20233489p20233489.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] Fuctions help!

2008-10-23 Thread Alex99

Hi everyone,

I have a question about functions. I have two functions:

Sampling=function(fname,Total,nSample,nPatient){..return(list(Gmean,Gsd))}

Power=function(alfa,m1,m2,s1,s2,n1,n2){return(powe)}

I want to use "Gmean" and "Gsd" which are the returned values from
"Sampling" function, in "Power" function.
i.e. when I call "power" I want to be able to have something like: 

Power(.05,Mmean,Gmean,Msd,Gsd,992,100)

Ps: Mmean and Gmean are the same size. Msd and Gsd are the size.

Thanks

-- 
View this message in context: 
http://www.nabble.com/Fuctions-help%21-tp20130620p20130620.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 with functions

2008-10-22 Thread Alex99

Hi there,

I have a the following function which takes a  name(fname), total number of
rows (Total), number of times to make a sample(nSample), number of
records/rows to be included in each sample(nPatient). then it generates
required samples and calculates the mean and standard deviation of the
columns for each sample and finally in calculates the grand mean and
standard deviation. 

The problem is if I run each line of the code separately (not in a function)
it works but when I put it in a function it doesn't!!!

i.e. if I delete the first line, and put "Mydata"(where ever I have fname)
and 900(where ever I have Total) and 5 (where ever I have nSample) and 100
(where ever I have nPatient) and run each line separately it works fine. But
when I make a function like the one below and call it like:
sampling(Mydata,900,5,100)
I get this error message: 
"Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array
extent"

I used "debug" on the sampling function it seems the error comes from line
4: 
"result=replicate(nSample,trans[,sample(colnames(trans),nPatient)],simplify=FALSE)"

any idea why do I get this error and how to fix it?
Thanks,

sampling=function(fname,Total,nSample,nPatient){
trans=t(A)
colnames(trans) <- c(1:Total)
result=replicate(nSample,trans[,sample(colnames(trans),nPatient)],simplify=FALSE)
show(result)

Means=do.call(rbind,lapply(result,function(x) rowMeans(x)))
rownames(Means)=paste('sample',1:nSample,sep="")
show(Means)
Gmean=colMeans(Means)
Gmean

# load genefilter package
STDs=do.call(rbind,lapply(result,function(x) rowSds(x)))
rownames(STDs)=paste('sample',1:nSample,sep="")
show(STDs)
Gsd=sd(STDs)
Gsd

return(Gmean,Gsd)}
-- 
View this message in context: 
http://www.nabble.com/Help-with-functions-tp20113920p20113920.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] Error in sample(colnames(B), 10) : invalid 'x' argument

2008-10-21 Thread Alex99

HI,

I have a file named "s1"(which has 14 rows and 4 columns) which is in csv
format. I import and call it "A" the file using:

A <- read.csv(file="s1.csv",head=TRUE,sep=",")

then I transpose it and call it "B"(which will have 4 rows and 14 columns)
using:

B=t(A)

when I want to make 5 samples from "B" (choosing 10 columns) using: 

result=replicate(5,B[,sample(colnames(B),10)],simplify=FALSE)

I get the following error:

"Error in sample(colnames(B), 10) : invalid 'x' argument"

anyone has any idea,why?and how to fix it?

Thanks
-- 
View this message in context: 
http://www.nabble.com/Error-in-sample%28colnames%28B%29%2C-10%29-%3A-invalid-%27x%27-argument-tp20094713p20094713.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] Inserting a new row in a matrix

2008-10-21 Thread Alex99

Hi guys,

I need to insert a row to a matrix in a for loop. I have matrix named "Avg"
which is a 5x4 matrix of zeros. 
I have a file named "A"(4 rows,14 columns) which I make a sample of it 5
times. each time I get the mean for each column and put the result in the
"Avg" matrix. this is my code:

Avg=matrix(0,5,4)
> 
>  for(i in 1:5){
+  res=(A[sample(nrow(A), 5),])
+  insertRow(Avg,i,colMeans(res))
+  show(res)
+  show(Avg)
+  }

this is my result(I just copied the first sample) :

s1 s2 s3 s4
21  0  1  0
30  0  0  0
11  0  0  0  0
50  1  0  1
12  0  0  0  0
 [,1] [,2] [,3] [,4]
[1,]0000
[2,]0000
[3,]0000
[4,]0000
[5,]0000

it's suppose to put .2 .2 .2 .2 in the first row of the matrix but as you
see it's all 0. any idea why and how to fix it?

Thanks,

-- 
View this message in context: 
http://www.nabble.com/Inserting-a-new-row-in-a-matrix-tp20096320p20096320.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] calculating mean for samples

2008-10-20 Thread Alex99

Hi everyone,
> does any one knows how can I calculate mean for different samples
> i.e. I have a data like this:
>
>  s1 s2 s3 s4
> 1   0  0  0  1
> 2   1  0  1  0
> 3   0  0  0  0
> 4   0  0  0  0
> 5   0  1  0  1
> 6   1  0  0  0
> 7   0  0  0  0
> 8   0  0  0  0
> 9   0  0  0  0
> 10  0  0  0  1
>
> I need to make 5 different sample with 5 different persons(rows) in each
> sample from it keeping s1,s3,s3,s4 but changing rows. and then calculate
> the mean for each "S" in each sample. and finally calculate the grand
> mean,which is the mean of means for each sample. i.e. if I sample 5 time I
> get 5 different means for s1, s2, s3, s4. then I need to add all five
> means for and divide it by 5.(of course I have to do it for s1,s2,s3,s4
> separately) 
-- 
View this message in context: 
http://www.nabble.com/calculating-mean-for-samples-tp20075174p20075174.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] Row Sampling

2008-10-20 Thread Alex99


Hi everyone,
does any one knows how can I make sample from rows?
i.e. I have a data like this:

 s1 s2 s3 s4
1   0  0  0  1
2   1  0  1  0
3   0  0  0  0
4   0  0  0  0
5   0  1  0  1
6   1  0  0  0
7   0  0  0  0
8   0  0  0  0
9   0  0  0  0
10  0  0  0  1

I need to make 5 different sample with 5 different persons(rows) in each
sample from it keeping s1,s3,s3,s4 but changing rows. I cant get "replicate"
or "sample" functions to make samples by changing the rows.

Thanks

-- 
View this message in context: 
http://www.nabble.com/Row-Sampling-tp20067830p20067830.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] function help

2008-10-17 Thread Alex99

Hi everyone,
I have dataset which I make a sample of it couple of times and each time I
get the mean and standard deviation of each row for each sample. I have a
function for that, which takes the name of the file and number of times to
sample and then returns the mean and standard deviation for each row in each
sample.

Sample=function(name, n){
res=replicate(n,name[,sample(colnames(name),n)],simplify=FALSE)

Means=do.call(rbind,lapply(res,function(x) rowMeans(x)))
rownames(Means)=paste('sample',1:n,sep="")
Gmean=colMeans(Means)

STDs=do.call(rbind,lapply(res,function(x) rowSds(x)))
rownames(STDs)=paste('sample',1:5,sep="")
Gsd=sd(STDs)

return(Gmean,Gsd)}

I then need to use the mean and standard deviation from each row to
calculate the Power for 2 sample means. here is the function I use to do it:

Power=function(alfa,m1,m2,s1,s2,n1,n2){
 up=abs(m1-m2)
 down=sqrt(((s1^2)/(n1))+((s2^2)/(n2)))
 z=(-1)*(qnorm(1-(alfa/2)))
 fi=z+(up/down)
 pow=pnorm(fi)
 return(pow)}

then I need to call the Power function:

Power(.05,57,mi,33,si,200,n)

the alfa,m1,s1 and n1 values are constant but the m2,s2 and n2 values are
changing.
n2 is the n used in sample function(which I could input manually)
m2 should be the grand mean for each row 
s2 is the grand standard deviation for each row

example:this is a sample output for "sample" function:
$Gmean
  s1   s2   s3   s4 
0.08 0.20 0.12 0.20 

$Gsd
   s1s2s3s4 
0.2449490 0.2156741 0.2449490 0.2156741 
 my problem is how can I put the corresponding means and standard devotions
together  in the power function?I used a for loop, but the problem is
getting the s1...s4 from Gmean and Gsd

Thanks for your help

 
-- 
View this message in context: 
http://www.nabble.com/function-help-tp20035949p20035949.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] saving result of a "for" loop

2008-10-16 Thread Alex99

Thanks a lot Stephen. It worked for me. also Jorge had a solution, it's a
short and easy code. U could have a look in case U want to use it in future.
Thanks again for all your help


stephen sefick wrote:
> 
> a <- c(1:10)
> b <- c(.5, .6, .9, 10, .4, 3, 4, 9, 0, 11)
> d <- c(21:30)
> 
> z <- data.frame(a,b,d)
> library(fields)
> results <- c()
> for(i in 1:(length(rownames(z))-1)){
>  results[i] <- rdist(z[i,], z[(i+1),])
>  }
> 
> results.1 <- data.frame(results)
>  f <- rownames(z)
>  r <- f[-1]
>  rownames(results.1) <- r
>  colnames(results.1) <- f[1]
> 
> This is a for loop that I used not too long ago defining the results
> outside of the loop worked for me.
> hope this helps
> 
> stephen
> 
> On Thu, Oct 16, 2008 at 9:10 AM, Alex99 <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hi everyone,
>> I have dataset which I take random samples of it 5 times. each time I get
>> the mean for rows for each sample.
>> at the end I need to calculate the Average of all means for  each sample
>> and
>> each row. to clear it up I give an example:
>> say this is my dataset.
>>X8 X9X10X12 X13 X14 X15 X16X17X18X19 X20 X21 X22
>> s1  0  1   000100000000
>> s2  0  0   001000000010
>> s3  0  1   000000000010
>> s4  1  0   001000010000
>>
>> I get a random sample and mean of row for that sample(5 times , but I
>> just
>> put 2 of them here to give you   an idea)
>>
>>X12 X9 X10
>> s10  1   0
>> s20  0   0
>> s30  1   0
>> s40  0   0
>>   s1s2s3s4
>> 0.333 0.000 0.333 0.000
>>
>>X10 X18 X8
>> s100  0
>> s200  0
>> s300  0
>> s401  1
>>  s1s2s3s4
>> 0.000 0.000 0.000 0.667
>>
>> This is the code I used:
>>  for(i in 1:5)
>>  {
>>   temp<-sample(A3,3, replace=F)
>>   Avg=rowMeans(temp)
>>   show(temp)
>>   show(Avg)
>>  }
>>
>> Now, the problem is how can I save the result for each row(s1,s2,s3,s4)
>> so
>> that I can get the grand average from 5 runs?I thought about using a
>> vector
>> in the "for" loop but it's no good, it over right so basically I only get
>> the means for last sample. any idea how to do it?
>> Thanks a lot
>>
>> --
>> View this message in context:
>> http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20013519.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.
>>
> 
> 
> 
> -- 
> Stephen Sefick
> Research Scientist
> Southeastern Natural Sciences Academy
> 
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods.  We are mammals, and have not exhausted the
> annoying little problems of being mammals.
> 
>   -K. Mullis
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20015119.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] saving result of a "for" loop

2008-10-16 Thread Alex99

Jorge you are awesome,

This code is very efficient.  it's exactly what I wanted to do and it's very
short and not complicated. 

Thanks a lot

Jorge Ivan Velez wrote:
> 
> Dear Alex,
> Is this what you want?
> 
> my=read.table(textConnection("
> X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
> 0  1   000100000000
> 0  0   001000000010
> 0  1   000000000010
> 1  0   00100001000
>  0"),header=TRUE)
> closeAllConnections()
> rownames(my)=paste('s',1:4,sep="")
> 
> # Five samples
> res=replicate(5,my[,sample(colnames(my),5)],simplify=FALSE)
> 
> # mean for each sample
> Means=do.call(rbind,lapply(res,function(x) rowMeans(x)))
> rownames(Means)=paste('sample',1:5,sep="")
> Means
> 
> # Global mean for sample
> colMeans(Means)
> 
> 
> HTH,
> 
> Jorge
> 
> 
> On Thu, Oct 16, 2008 at 9:10 AM, Alex99 <[EMAIL PROTECTED]> wrote:
> 
>>
>>
>> Hi everyone,
>> I have dataset which I take random samples of it 5 times. each time I get
>> the mean for rows for each sample.
>> at the end I need to calculate the Average of all means for  each sample
>> and
>> each row. to clear it up I give an example:
>> say this is my dataset.
>>X8 X9X10X12 X13 X14 X15 X16X17X18X19 X20 X21 X22
>> s1  0  1   000100000000
>> s2  0  0   001000000010
>> s3  0  1   000000000010
>> s4  1  0   001000010000
>>
>> I get a random sample and mean of row for that sample(5 times , but I
>> just
>> put 2 of them here to give you   an idea)
>>
>>X12 X9 X10
>> s10  1   0
>> s20  0   0
>> s30  1   0
>> s40  0   0
>>   s1s2s3s4
>> 0.333 0.000 0.333 0.000
>>
>>X10 X18 X8
>> s100  0
>> s200  0
>> s300  0
>> s401  1
>>  s1s2s3s4
>> 0.000 0.000 0.000 0.667
>>
>> This is the code I used:
>>  for(i in 1:5)
>>  {
>>   temp<-sample(A3,3, replace=F)
>>   Avg=rowMeans(temp)
>>   show(temp)
>>   show(Avg)
>>  }
>>
>> Now, the problem is how can I save the result for each row(s1,s2,s3,s4)
>> so
>> that I can get the grand average from 5 runs?I thought about using a
>> vector
>> in the "for" loop but it's no good, it over right so basically I only get
>> the means for last sample. any idea how to do it?
>> Thanks a lot
>>
>> --
>> View this message in context:
>> http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20013519.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.
>>
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20015092.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] saving result of a "for" loop

2008-10-16 Thread Alex99


Hi everyone,
I have dataset which I take random samples of it 5 times. each time I get
the mean for rows for each sample.
at the end I need to calculate the Average of all means for  each sample and
each row. to clear it up I give an example:
say this is my dataset.
X8 X9X10X12 X13 X14 X15 X16X17X18X19 X20 X21 X22
s1  0  1   000100000000
s2  0  0   001000000010
s3  0  1   000000000010
s4  1  0   001000010000

I get a random sample and mean of row for that sample(5 times , but I just
put 2 of them here to give you   an idea)

X12 X9 X10
s10  1   0
s20  0   0
s30  1   0
s40  0   0
   s1s2s3s4 
0.333 0.000 0.333 0.000 

X10 X18 X8
s100  0
s200  0
s300  0
s401  1
 s1s2s3s4 
0.000 0.000 0.000 0.667 

This is the code I used:
 for(i in 1:5) 
 {
   temp<-sample(A3,3, replace=F)
   Avg=rowMeans(temp)
   show(temp)
   show(Avg)
 }

Now, the problem is how can I save the result for each row(s1,s2,s3,s4) so
that I can get the grand average from 5 runs?I thought about using a vector
in the "for" loop but it's no good, it over right so basically I only get
the means for last sample. any idea how to do it?
Thanks a lot

-- 
View this message in context: 
http://www.nabble.com/saving-result-of-a-%22for%22-loop-tp20013519p20013519.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] Standard deviation for rows

2008-10-15 Thread Alex99

Thanks for the reply,

that's exactly what I wanted. I also figured that the function rowSds() does
exist. I just needed to load the generfilter package.

Thanks again.
 

Nutter, Benjamin wrote:
> 
> ?apply
> 
> e.g. apply(matrix,1,sd)
> 
> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Alex99
> Sent: Wednesday, October 15, 2008 1:17 PM
> To: r-help@r-project.org
> Subject: [R] Standard deviation for rows
> 
> 
> Hi everyone,
> 
> I have just started using R, and I have a simple question.
> How can I get the Standard deviation for rows. basically I am looking
> for
> something like  "rowMeans()"  
> but for Standard deviation (I tried "rowSds()" didn't exist)
> 
> Thanks,
> -- 
> View this message in context:
> http://www.nabble.com/Standard-deviation-for-rows-tp19998106p19998106.ht
> ml
> 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.
> 
> 
> 
> P Please consider the environment before printing this e-mail
> 
> Cleveland Clinic is ranked one of the top hospitals
> in America by U.S. News & World Report (2008).  
> Visit us online at http://www.clevelandclinic.org for
> a complete listing of our services, staff and
> locations.
> 
> 
> Confidentiality Note:  This message is intended for use\...{{dropped:13}}
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Standard-deviation-for-rows-tp19998106p1312.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] Standard deviation for rows

2008-10-15 Thread Alex99

Hi everyone,

I have just started using R, and I have a simple question.
How can I get the Standard deviation for rows. basically I am looking for
something like  "rowMeans()"  
but for Standard deviation (I tried "rowSds()" didn't exist)

Thanks,
-- 
View this message in context: 
http://www.nabble.com/Standard-deviation-for-rows-tp19998106p19998106.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] Help Help with sampling

2008-10-15 Thread Alex99

Thanks again Jorge,
but when I type in  lapply(res,function(x) rbind(rowMeans(x)) it's like it's
waiting for something else, it doesnt run. I tried "help(lapply)" to learn
more about lappy but didnt give me any result. could you tell me why it
doesnt run and what is lapply for?

Thanks a lot for all your help


Jorge Ivan Velez wrote:
> 
> Dear Alex,
> Is this what you want?
> 
> my=read.table(textConnection("
> X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
> 0  1   000100000000
> 0  0   001000000010
> 0  1   000000000010
> 1  0   00100001000
>  0"),header=TRUE)
> closeAllConnections()
> rownames(my)=paste('s',1:4,sep="")
> 
> # Using 5 samples only
> res=replicate(5,my[,sample(colnames(my),5)],simplify=FALSE)
> 
> # mean
> lapply(res,function(x) rbind(rowMeans(x))
> 
> # standard deviation
> lapply(res,function(x) apply(x,1,sd,na.rm=TRUE))
> 
> 
> HTH,
> 
> Jorge
> 
> 
> On Wed, Oct 15, 2008 at 10:58 AM, Alex99 <[EMAIL PROTECTED]> wrote:
> 
>>
>> Thanks for the reply Jorge,
>>
>> that works BUT the reason I didn't use it, is because I need to calculate
>> the mean and Standard deviation for S1,S2,S3 and S4 in each sample. which
>> means I'll have 5 means for S1, and 5 means for S2 and 5 means for S3 and
>> 5
>> means for S4 (and at the end I have to get the average of the means for
>> each
>> 'S').
>> I used the following:
>>
>> for(i in 1:5) {temp<-sample(A3,3, replace=F)
>> + Trans=t(temp)
>> + Avg=mean(Trans)
>> + show(temp)
>> + show(Trans)
>> + show(Avg)}
>>
>> the reason I used Transpose is to get the R to give me the mean for S's.
>> but
>> what I get is just one mean for each sample. not the mean for each S.
>> any suggestion how to do it?
>>
>> thanks again for all your help
>>
>> Jorge Ivan Velez wrote:
>> >
>> > Dear Alex,
>> > Is this what you want?
>> >
>> > # Data set
>> > my=read.table(textConnection("
>> > X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
>> > 0  1   000100000000
>> > 0  0   00100000    0    010
>> > 0  1   000000000010
>> > 1  0   00100001000
>> >  0"),header=TRUE)
>> > closeAllConnections()
>> > rownames(my)=paste('s',1:4,sep="")
>> >
>> > # Samples
>> > res=list()
>> > for(i in 1:5) res[[i]]<- my[,sample(colnames(my),5)]
>> > res
>> >
>> > HTH,
>> >
>> > Jorge
>> >
>> >
>> > On Wed, Oct 15, 2008 at 10:07 AM, Alex99 <[EMAIL PROTECTED]> wrote:
>> >
>> >>
>> >> Hi everyone,
>> >>
>> >> I have a dataset(named "Mydata") which includes 4 different variables
>> >> named;
>> >> s1,s2,s3,s4 .Each variable(symptom) has 14 patients.
>> >> I need to use random sampling to make, 5 different samples from my
>> data
>> >> with
>> >> 5 patients in each sample. i.e. using all 4 variables I need to make 5
>> >> different samples by changing patients(with 5 patients in each
>> sample).
>> >>
>> >>
>> >>   X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
>> >> s1  0  1   000100000000
>> >> s2  0  0   001000000010
>> >> s3  0  1   000000000010
>> >> s4  1  0   001000010000
>> >>
>> >>
>> >> I used this code:
>> >>
>> >> temp=list(NULL)
>> >> for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)
>> >>
>> >> but I get the following error:
>> >> "number of items to replace is not a multiple of replacement length"
>> >>
>> >> any idea why I get this eeror message and how can I fix it?
>> >> Thanks a lot.
>> >>
>> >> --
>> >> View this message in context:
>> >> http://www.nabble.com/Help-Help-w

Re: [R] Help Help with sampling

2008-10-15 Thread Alex99

Thanks for the reply Jorge,

that works BUT the reason I didn't use it, is because I need to calculate
the mean and Standard deviation for S1,S2,S3 and S4 in each sample. which
means I'll have 5 means for S1, and 5 means for S2 and 5 means for S3 and 5
means for S4 (and at the end I have to get the average of the means for each
'S').
I used the following:

for(i in 1:5) {temp<-sample(A3,3, replace=F)
+ Trans=t(temp)
+ Avg=mean(Trans)
+ show(temp)
+ show(Trans)
+ show(Avg)}

the reason I used Transpose is to get the R to give me the mean for S's. but
what I get is just one mean for each sample. not the mean for each S.
any suggestion how to do it?

thanks again for all your help 

Jorge Ivan Velez wrote:
> 
> Dear Alex,
> Is this what you want?
> 
> # Data set
> my=read.table(textConnection("
> X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
> 0  1   000100000000
> 0  0   001000000010
> 0  1   000000000010
> 1  0   00100001000
>  0"),header=TRUE)
> closeAllConnections()
> rownames(my)=paste('s',1:4,sep="")
> 
> # Samples
> res=list()
> for(i in 1:5) res[[i]]<- my[,sample(colnames(my),5)]
> res
> 
> HTH,
> 
> Jorge
> 
> 
> On Wed, Oct 15, 2008 at 10:07 AM, Alex99 <[EMAIL PROTECTED]> wrote:
> 
>>
>> Hi everyone,
>>
>> I have a dataset(named "Mydata") which includes 4 different variables
>> named;
>> s1,s2,s3,s4 .Each variable(symptom) has 14 patients.
>> I need to use random sampling to make, 5 different samples from my data
>> with
>> 5 patients in each sample. i.e. using all 4 variables I need to make 5
>> different samples by changing patients(with 5 patients in each sample).
>>
>>
>>   X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
>> s1  0  1   000100000000
>> s2  0  0   001000000010
>> s3  0  1   000000000010
>> s4  1  0   001000010000
>>
>>
>> I used this code:
>>
>> temp=list(NULL)
>> for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)
>>
>> but I get the following error:
>> "number of items to replace is not a multiple of replacement length"
>>
>> any idea why I get this eeror message and how can I fix it?
>> Thanks a lot.
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Help-Help-with-sampling-tp19994275p19994275.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.
>>
> 
>   [[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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Help-Help-with-sampling-tp19994275p19995327.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] Help Help with sampling

2008-10-15 Thread Alex99

Thanks for the reply Peter, 

that works BUT the reason I didn't use it, is because I need to calculate
the mean and Standard deviation for S1,S2,S3 and S4 in each sample. which
means I'll have 5 means for S1, and 5 means for S2 and 5 means for S3 and 5
means for S4 (and at the end I have to get the average of the means for each
'S').
I used the following:

for(i in 1:5) {temp<-sample(A3,3, replace=F)
+ Trans=t(temp)
+ Avg=mean(Trans)
+ show(temp)
+ show(Trans)
+ show(Avg)}

the reason I used Transpose is to get the R to give me the mean for S's. but
what I get is just one mean for each sample. not the mean for each S.
any suggestion how to do it?

thanks again for all your help


Peter Dalgaard wrote:
> 
> Alex99 wrote:
>> Hi everyone,
>>
>> I have a dataset(named "Mydata") which includes 4 different variables
>> named;
>> s1,s2,s3,s4 .Each variable(symptom) has 14 patients.
>> I need to use random sampling to make, 5 different samples from my data
>> with
>> 5 patients in each sample. i.e. using all 4 variables I need to make 5
>> different samples by changing patients(with 5 patients in each sample).
>>
>>
>>X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
>> s1  0  1   000100000000
>> s2  0  0   001000000010
>> s3  0  1   000000000010
>> s4  1  0   001000010000
>>
>>
>> I used this code:
>>
>> temp=list(NULL)
>> for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)
>>
>> but I get the following error:
>> "number of items to replace is not a multiple of replacement length"
>>
>> any idea why I get this eeror message and how can I fix it?
>> Thanks a lot.
>>
>>   
> The direct cause is that you are not using temp[[i]]<-, but I don't
> think that sample() construct does what I think you think it does
> either. You might want to use replicate() instead, as in
>  
>  replicate(2,airquality[sample(1:153,5, replace=F),], simplify=F)
> 
> -- 
>O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
>   c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
>  (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
> ~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Help-Help-with-sampling-tp19994275p19995210.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 Help with sampling

2008-10-15 Thread Alex99

Hi everyone,

I have a dataset(named "Mydata") which includes 4 different variables named;
s1,s2,s3,s4 .Each variable(symptom) has 14 patients.
I need to use random sampling to make, 5 different samples from my data with
5 patients in each sample. i.e. using all 4 variables I need to make 5
different samples by changing patients(with 5 patients in each sample).


   X8 X9 X10 X102 X110 X177 X283 X284 X286 X292 X297 X306 X308 X314
s1  0  1   000100000000
s2  0  0   001000000010
s3  0  1   000000000010
s4  1  0   001000010000


I used this code:

temp=list(NULL)
for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)

but I get the following error:
"number of items to replace is not a multiple of replacement length"

any idea why I get this eeror message and how can I fix it?
Thanks a lot.

-- 
View this message in context: 
http://www.nabble.com/Help-Help-with-sampling-tp19994275p19994275.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] Question: how to make a sample from my data set

2008-10-14 Thread Alex99

 Hi everyone,

I have a question about sampling. I have a data set which includes 25
different variables named; symptom1, symptom2,.,symptom25(25
columns).Each variable(symptom) has 9 patients (9 columns). 
I need to use random sampling to make, 5 different samples from my data.
i.e. using all 25 variables I need to make 10 different samples by changing
the rows(patients) and then I need to show each sample with their mean for
each variable(symptom) which is just adding a row at the end of each symptom
to show the mean.

I used this code:
for(i in 1:5) {temp[i]<-sample(Mydata,5, replace=F)} show(temp)
-- 
View this message in context: 
http://www.nabble.com/Question%3A-how-to-make-a-sample-from-my-data-set-tp19974192p19974192.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] Sampling

2008-10-10 Thread Alex99

Hi Guys,
I am in desperate need with sampling. I am suppose to sample from a dataset.
I use the following code:

> for(i in 1:5){temp[i]<-sample(T2,40,replace=F)
+ show(temp)}

but all the samples are the same, but I want them to be different.any
suggestion? 

Thanks


-- 
View this message in context: 
http://www.nabble.com/Sampling-tp19923768p19923768.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.