[R] How to sum only a few elements in a line

2009-11-25 Thread Marcio Resende
Hello, I have a matrix with the numbers 0,1 and 9 I would like to write a function that could sum each line skiping everytime a number 9 appears for example [0 1 0 1 1 9 1] the sum would be 4. However I cannot replace 9 by 0 otherwise after the sum is done I wouldn´t be able to distiguish which o

[R] Is there a faster way to do it?

2009-10-28 Thread Marcio Resende
#Mdarts is a matrix 2343x788 #frequencia is a vector 2343x1 # 9 in Mdarts[fri,frj] stands for my missing values which i want to replace by the value in the vector frequencia Mdarts<-t(matrix(scan("C:/GWS/CNB/dartg.txt"),ncol=nindT,nrow=nm, byrow=T)) frequencia <- matrix(scan("C:/GWS/CNB/freq.txt

[R] Sampling procedure

2009-10-15 Thread Marcio Resende
I would like to divide a vector in 9 groups in a way that each number is present in only one group. In a vector of 783 I would like to divide in 9 different groups of 87 Example <- matrix(c(1:783),ncol = 1) s1 <- as.matrix(sample(Example,87, re = FALSE)) Example <- Example[-s1] s2 <- as.matrix(sa

[R] help with loops

2009-10-14 Thread Marcio Resende
Hi guys, my doubt is quite simple, I´ll try to explain: test = matrix(0, nrow = 783, ncol = 12) for (x in 1:9){ for (y in 1:12){ ### In the original script for each y its generated a vector (87x1) ### 87 times 9(x) = 783 (equals the number of rows I want to fill in the "test" matrix } } W

[R] Count number of zeros in a collumn

2009-09-27 Thread Marcio Resende
I have a matrix 700x2000 which is sampled in each cycle from another matrix 788x2000 with the numbers 0,1 and 9 There is one specific collumn of this matrix, dart[,1977], that usually, after the samplimg procedure has only 1 and 9 (because the zero frequency in this collumn is low). However, when

Re: [R] Check value interval in a if loop

2009-09-27 Thread Marcio Resende
Hi Lucas, try: if(pvalue>0.05 & pvalue<0.1) HTH Marcio Lucas Sevilla García wrote: > > > Hi R community > > I have a little problem, and I tried to solve it by myself but I couldn't. > I building an if loop, and I want to check a value inside an interval. > This would be the case: > > pv

Re: [R] for cycle with uncontinuous numbers

2009-09-27 Thread Marcio Resende
g it to do with the script you > provided. > > On Sun, Sep 27, 2009 at 10:09 AM, Marcio Resende > wrote: >> >> Hi Tobias, thanks for the help, >> the code I am using is quite long, but basically what I tried to do was >> >> test <- matrix(0,6,1) &g

Re: [R] for cycle with uncontinuous numbers

2009-09-27 Thread Marcio Resende
Hi Tobias, thanks for the help, the code I am using is quite long, but basically what I tried to do was test <- matrix(0,6,1) x <- matrix( c(50,100,200,300,900,2343) ,ncol = 1) for (i in x){ test [i] <- (i) } but this code returns NA for all the elements which are not x Tobias Verbeke-2 w

Re: [R] Teach me how to transpose in R

2009-09-27 Thread Marcio Resende
Hi Hyo, I am kinda of new in R but I think if you use x <- as.matrix(data2) #with the numer of collumns you wish y <- t(x) it should work Hope I´ve helped Márcio Hyo Lee wrote: > > Hi guys, > I need your help!! > > My goal is to make a csv file from ncdf file. > This is the code i've used

[R] for cycle with uncontinuous numbers

2009-09-27 Thread Marcio Resende
Hi nice people, I would like to do a for cycle but i wish it to assume only the numers 50, 100, 200, 300, 900 and 2343 I tried to do something like x <- c(50,100,200,300,900,2343) for (i in x){ #. } But it didn´t work Could anybody help me? Thanks in advance Marcio -- View this message in c

[R] Sum of Product in a Matrix

2009-09-22 Thread Marcio Resende
Hi, I am new in R and I don´t know how to sum the product of two elements at the time in a matrix X=[ 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16] I would like to do (1*5+2*6+3*7+4*8) I need to do it step by step because I will further put a conditional in the formula

Re: [R] BLUP with missing data

2009-09-22 Thread Marcio Resende
Sorry, I sent it quickly and forgot to thank in advance Marcio Marcio Resende wrote: > > hello guys, I need to do a BLUP in the simplest model > y = Xm + Zg + e > however I have missing data in the analysis which I can´t consider as > 0(zero). So I need to generate the matrix X

[R] BLUP with missing data

2009-09-22 Thread Marcio Resende
hello guys, I need to do a BLUP in the simplest model y = Xm + Zg + e however I have missing data in the analysis which I can´t consider as 0(zero). So I need to generate the matrix X'Z, Z'X and Z'Z step by step; I can´t use crossprod(x) #neither X'X <- t(x)%*%x because I should skip the element

[R] chage the output file name

2009-09-22 Thread Marcio Resende
After I run my script I save all my output e.g. write.table(d, file = "C:/PINEheight.txt) write.table(v, file = "C:/PINEvolume.txt) write.table(v, file = "C:/PINEdiameter.txt) write.table(v, file = "C:/PINEdensity.txt) and then I would like to run again with another tree and save again e.g write

[R] Incorrect Dimension

2009-09-17 Thread Marcio Resende
I am new in R and i am having trouble here. I´ve already searched in the list but hasn´t helped When i run this script above i get the message "Error in gen[j, i] : incorrect number of dimensions". However gen is 1000x200 (ind x loc) and so is g could anybody help me for (i in 1 : loc) { #l

[R] How to separate a function by 2 probabilities

2009-09-17 Thread Marcio Resende
Good Mourning, I have a function to generate a matrix as I show part of it; g[j,i]<-if (gen[j,i]==0) al1[i,1]+al1[i,1] else ... However i would like that this function occurred with a probability P and that another function (another formula to generate g matrix) with probability P-1 That´s it,