Re: [R] looping in R

2014-04-02 Thread Duncan Murdoch

On 02/04/2014, 3:15 PM, Abugri James wrote:

I ran the following loop on my SNP data and got an error message as
indicated


I would assume that the error message is accurate: 
as.character(current[1, "gene_old"]) has length zero.  You'll need to 
debug why that happened.


Duncan Murdoch


for (i in genenames){
+   current <- fst1[which(fst1$Gene == i),]
+   num <- nrow(current)
+   fst <- max(current$fst)
+   position <- mean(current$pos)
+   nposition <- mean(current$newpos)
+   numhigh <- nrow(current[which(current$fst > threshold),])
+   colors <- mean(current$colors)
+   output <- matrix(NA,nrow=1,ncol=8)
+   numthresh <- paste("# SNPs > Fst = ", threshold, sep="")
+   colnames(output) <- c("gene", "gene_old", "pos", "newpos", "# Snps",
numthresh, "Max.Fst", "colors")
+   output[1,1] <- i
+   output[1,2] <- as.character(current[1, "gene_old"])
+   output[1,3] <- position
+   output[1,4] <- nposition
+   output[1,5] <- num
+   output[1,6] <- numhigh
+   output[1,7] <- fst
+   output[1,8] <- colors
+   maxfstgene <- rbind(maxfstgene, output)
+ }
Error in output[1, 2] <- as.character(current[1, "gene_old"]) :
   replacement has length zero
In addition: Warning message:
In mean.default(current$pos) :
   argument is not numeric or logical: returning NA
--



__
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] looping in R

2014-04-02 Thread Jeff Newmiller
You desperately need to read the Posting Guide (mentioned in the footer of this 
email) which warns you not to post in HTML format, and learn how to make a 
reproducible example (e.g. 
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example).

The problem lies in some interaction between your data and code, and without 
both we cannot help you.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On April 2, 2014 12:15:51 PM PDT, Abugri James  wrote:
>I ran the following loop on my SNP data and got an error message as
>indicated
>for (i in genenames){
>+   current <- fst1[which(fst1$Gene == i),]
>+   num <- nrow(current)
>+   fst <- max(current$fst)
>+   position <- mean(current$pos)
>+   nposition <- mean(current$newpos)
>+   numhigh <- nrow(current[which(current$fst > threshold),])
>+   colors <- mean(current$colors)
>+   output <- matrix(NA,nrow=1,ncol=8)
>+   numthresh <- paste("# SNPs > Fst = ", threshold, sep="")
>+   colnames(output) <- c("gene", "gene_old", "pos", "newpos", "#
>Snps",
>numthresh, "Max.Fst", "colors")
>+   output[1,1] <- i
>+   output[1,2] <- as.character(current[1, "gene_old"])
>+   output[1,3] <- position
>+   output[1,4] <- nposition
>+   output[1,5] <- num
>+   output[1,6] <- numhigh
>+   output[1,7] <- fst
>+   output[1,8] <- colors
>+   maxfstgene <- rbind(maxfstgene, output)
>+ }
>Error in output[1, 2] <- as.character(current[1, "gene_old"]) :
>  replacement has length zero
>In addition: Warning message:
>In mean.default(current$pos) :
>  argument is not numeric or logical: returning NA
>--

__
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] looping in R

2014-04-02 Thread Abugri James
I ran the following loop on my SNP data and got an error message as
indicated
for (i in genenames){
+   current <- fst1[which(fst1$Gene == i),]
+   num <- nrow(current)
+   fst <- max(current$fst)
+   position <- mean(current$pos)
+   nposition <- mean(current$newpos)
+   numhigh <- nrow(current[which(current$fst > threshold),])
+   colors <- mean(current$colors)
+   output <- matrix(NA,nrow=1,ncol=8)
+   numthresh <- paste("# SNPs > Fst = ", threshold, sep="")
+   colnames(output) <- c("gene", "gene_old", "pos", "newpos", "# Snps",
numthresh, "Max.Fst", "colors")
+   output[1,1] <- i
+   output[1,2] <- as.character(current[1, "gene_old"])
+   output[1,3] <- position
+   output[1,4] <- nposition
+   output[1,5] <- num
+   output[1,6] <- numhigh
+   output[1,7] <- fst
+   output[1,8] <- colors
+   maxfstgene <- rbind(maxfstgene, output)
+ }
Error in output[1, 2] <- as.character(current[1, "gene_old"]) :
  replacement has length zero
In addition: Warning message:
In mean.default(current$pos) :
  argument is not numeric or logical: returning NA
--

-- 
* "The information contained in this email and any attachments may be 
legally privileged and confidential. If you are not an intended recipient, 
you are hereby notified that any dissemination, distribution, or copying of 
this e-mail is strictly prohibited. If you have received this e-mail in 
error, please notify the sender and permanently delete the e-mail and any 
attachments immediately. You should not retain, copy or use this e-mail or 
any attachments for any purpose, nor disclose all or any part of the 
contents to any other person."*

[[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.