[R] as.numeric question

2006-04-27 Thread Paulo Brando
Dear all, 
 
Is there a way of keeping the actual information in a factor when
converting it to numeric? 
 
Example:
 
What I want:
 
as.numeric(factor(5:10))
5, 6, 7, 8, 9, 10
 
 
How R works:
 
as.numeric(factor(5:10)) #R example on 'as.numeric'
[1] 1 2 3 4 5 6
 
Thank you very much.
 
Paulo

Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 3522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]
 
 

[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RES: survival

2006-03-08 Thread Paulo Brando
  28  30
interaction(parcel2, sp2)=1.5 15744   7142 33  32  34


Sorry, but I still cannot find what is going wrong.

Regards,

Paulo 

-Mensagem original-
De: Thomas Lumley [mailto:[EMAIL PROTECTED] 
Enviada em: Wednesday, March 08, 2006 9:15 AM
Para: Paulo Brando
Cc: r-help@stat.math.ethz.ch
Assunto: Re: [R] survival

On Wed, 8 Mar 2006, Paulo Brando wrote:

 Dear R-helpers,

 We marked 6000 leaves from 5 SPECIES - 10 individuals/species - in two
 different TREATMENTs: a control and a dry-plot from which 50% of
 incoming precipitation was excluded. We followed those leaves for 42
 months and noted the presence and absence at each visit. I then
carried
 out a Cox Harzard model to see differences in leaf mortality between
 parcels and among species over time:

 leaves.cox - coxph(Surv(time, censo) ~ treatment + species, data=
wsuv)


 When I plot 'survfitt(leaves.cox)', I come up with a survivor curve
that
 starts at 1 ends at 0.4. The problem is that at time 42 almost all
 leaves are dead. I wander if surfit plot at time 42 should also be
close
 to zero?

Yes, it probably should.

It is a bit hard to tell what is going wrong, though.  If you do

plot(survfit(Surv(time,censo)~1,data=wsuv)
plot(survfit(Surv(time,censo)~species,data=wsuv)
plot(survfit(Surv(time,censo)~treatment,data=wsuv)
plot(survfit(Surv(time,censo)~interaction(treatment,species),data=wsuv)

you will get Kaplan-Meier estimates of survival curves. Looking at these

may tell you what is happening.

-thomas


 I followed examples from Venables and Ripley' book. (These analysis
are
 quite new for me).

 summary(leaves.cox)

 Call:
 coxph(formula = Surv(time, censo) ~ (treatment) + species, data =
wsuv)

 n= 140840
   coef exp(coef) se(coef) z p
 treatment  -0.0209  0.98  0.00847 -2.47 0.014
 species 0.0712  1.07  0.00296 24.07 0.000

exp(coef) exp(-coef) lower .95 upper .95
 treatment0.98  1.021 0.963 0.996
 species  1.07  0.931 1.068 1.080

 Rsquare= 0.004   (max possible= 1 )
 Likelihood ratio test= 590  on 2 df,   p=0
 Wald test= 587  on 2 df,   p=0
 Score (logrank) test = 588  on 2 df,   p=0


 My best regards and thanks in advance!

 Paulo
 
 Paulo M. Brando
 Instituto de Pesquisa Ambiental da Amazonia (IPAM)
 Santarem, PA, Brasil.
 Av. Rui Barbosa, 136.
 Fone: + 55 93 3522 55 38
 www.ipam.org.br
 E-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RES: How to read an excel data into R?

2005-06-23 Thread Paulo Brando
Hi ling, save your file as 'csv'.

I always use the following script:


NAME - read.table(C:LOCATION/FILE NAME.csv, header = TRUE,  sep =
,, na.string=.)




Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]



-Mensagem original-
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Em nome de Ling Jin
Enviada em: Wednesday, June 22, 2005 4:47 PM
Para: r-help@stat.math.ethz.ch
Assunto: [R] How to read an excel data into R?

Hi all,

Does anybody know the easiest way to import excel data into R? I copied 
and pasted the excel data into a txt file, and tried read.table, but R 
reported that

Error in read.table(data_support.txt, sep =  , header = T) :
 more columns than column names

Thanks!

Ling

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RES: another aov results interpretation question

2005-06-20 Thread Paulo Brando

Dear All,

I created a script to calculate averages - two groups: parcel and
date - and, based on these averages, make a graph. The problem is that
'R' does not recognize the first column even if I try to insert one. 

A brief example

Raw data: 

Data - sample(1:100, 30, replace = FALSE, prob = NULL)
Date - rep(c(02/30/2004,03/15/2004, 04/16/2004, 06/14/2004,
07/08/2004), 6)
Parcel - rep(c(DRY, CONTROL),15)

Df - data.frame(Parcel, Date, Data)

Res - tapply(Df$Data, list(Date = Df$Date, Parcel = Df$Parcel), mean) 


 Res
Parcel
Date  CONTROL  DRY
  02/30/2004 53.0 52.3
  03/15/2004 54.0 67.7
  04/16/2004 54.7 30.0
  06/14/2004 27.7 20.0
  07/08/2004 59.0 38.0

 colnames(Res)
[1] CONTROL DRY

 matplot(Res[,1], Res[,-1], type = l) 

### It does not recognize the colunm Date. Why?

Thanks in advance!

Paulo


Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RES: Learning, if and else

2005-06-14 Thread Paulo Brando
Thank you very much! All methods are very useful. 


Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]



-Mensagem original-
De: Adaikalavan Ramasamy [mailto:[EMAIL PROTECTED] 
Enviada em: Tuesday, June 14, 2005 3:17 AM
Para: Paulo Brando
Cc: R-help@stat.math.ethz.ch
Assunto: Re: [R] Learning, if and else

You can also use switch() instead of ifelse(), which makes the code a
bit easier to read. The downside to this is that switch does not take
vectorised input and thus you need a loop. For example

 # data
 dbh  - c(30,29,15,14,30,29)
 form - factor(c(tree, tree, liana, liana, palm, palm)) 
 df   - data.frame(dbh, form)
 
 out - numeric( nrow(df) )
 for(i in 1:nrow(df)){
 
   x - as.numeric( df[i, 1] )
   y - as.character( df[i, 2] )

   out[i] - switch( y,
  tree  = exp( -4.898 + 4.512*log(x) - 0.319*(log(x))^2 ),
  liana = 10^(0.07 + 2.17 * log10(x)),
  NA
   )
 }


Or slightly more efficient solution is

 out - apply( df, 1, function(z){
   x - as.numeric(z[1]); y - as.character(z[2])
   
   switch( y,
  tree  = exp( -4.898 + 4.512*log(x) - 0.319*(log(x))^2 ),
  liana = 10^(0.07 + 2.17 * log10(x)),
  NA
  )
 })

Regards, Adai



On Mon, 2005-06-13 at 15:32 -0700, Paulo Brando wrote:
 Dear Rs,
 
 I have tried to use conditional expressions to calculate biomass for
 different life forms (trees, lianas, and palms).
 
 Here is an example:
 
  lifeform
 
 dbh  form
 1   30  tree
 2   29  tree
 3   28  tree
 4   27  tree
 5   26  tree
 6   25  tree
 7   24  tree
 8   23  tree
 9   22  tree
 10  21  tree
 11  20  tree
 12  15 liana
 13  14 liana
 14  13 liana
 15  12 liana
 16  11 liana
 17  10 liana
 18   9 liana
 19   8 liana
 20   7 liana
 21   6 liana
 22   5 liana
 23  30  palm
 24  29  palm
 25  28  palm
 26  27  palm
 27  26  palm
 28  25  palm
 29  24  palm
 30  23  palm
 31  22  palm
 32  21  palm
 33  20  palm
 
 ### I want to include biomass 
 
 lifeform$biomass - 
 
 {
   if(lifeform$form==tree)
exp(-4.898+4.512*log(dbh)-0.319*(log(dbh))^2) 
else{ 
 if (lifeform$form==liana)
10^(0.07 + 2.17 * log10 (dbh))
else (NA)
 }
 Warning message:
 the condition has length  1 and only the first element will be used
in:
 if (lifeform$form == tree) exp(-4.898 + 4.512 * log(dbh) -
 
 
 ### But I always get the message warning message above. 
 
 
 
 I looked for similar examples in R mail list archive, but they did not
 help a lot.
 
 I am quite new to 'R'. Any material that covers this theme?
 
 Thank you very much!
 
 Paulo
 
 PS. Sorry about the last e-mail. I did not change the message title.
 
 Paulo M. Brando
 Instituto de Pesquisa Ambiental da Amazonia (IPAM)
 Santarem, PA, Brasil.
 Av. Rui Barbosa, 136.
 Fone: + 55 93 522 55 38
 www.ipam.org.br
 E-mail: [EMAIL PROTECTED]
 
 __
 R-help@stat.math.ethz.ch mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html


__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] RES: install R 2.1.0 patched from source on FC3

2005-06-13 Thread Paulo Brando

Dear Rs,

I have tried to use conditional expressions to calculate biomass for
different life forms (trees, lianas, and palms).

Here is an example:

 lifeform

dbh  form
1   30  tree
2   29  tree
3   28  tree
4   27  tree
5   26  tree
6   25  tree
7   24  tree
8   23  tree
9   22  tree
10  21  tree
11  20  tree
12  15 liana
13  14 liana
14  13 liana
15  12 liana
16  11 liana
17  10 liana
18   9 liana
19   8 liana
20   7 liana
21   6 liana
22   5 liana
23  30  palm
24  29  palm
25  28  palm
26  27  palm
27  26  palm
28  25  palm
29  24  palm
30  23  palm
31  22  palm
32  21  palm
33  20  palm

### I want to include biomass 

lifeform$biomass - 

{
  if(lifeform$form==tree)
   exp(-4.898+4.512*log(dbh)-0.319*(log(dbh))^2) 
   else{ 
if (lifeform$form==liana)
   10^(0.07 + 2.17 * log10 (dbh))
   else (NA)
}
Warning message:
the condition has length  1 and only the first element will be used in:
if (lifeform$form == tree) exp(-4.898 + 4.512 * log(dbh) -


### But I always get the message warning message above. 



I looked for similar examples in R mail list archive, but they did not
help a lot.

I am quite new to 'R'. Any material that covers this theme?

Thank you very much!

Paulo

Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]



-Mensagem original-
De: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Em nome de Peter Dalgaard
Enviada em: Monday, June 13, 2005 9:04 AM
Para: Weiwei Shi
Cc: R-help@stat.math.ethz.ch
Assunto: Re: [R] install R 2.1.0 patched from source on FC3

Weiwei Shi [EMAIL PROTECTED] writes:

 Hi, 
 I have some problem when I tried to install R from source:
 work as root
 cd /root/dls/R-patched # this is where I unzip the file:
 R-patched_2005-06-08.tar.gz
 make clean
 
 # i need my R_HOME=/usr/lib/R and I need to create libR.so for
 RSPython, so I did:
 ./configure --prefix=/usr/lib/R --enable-R-shlib   
 make
 
 But I found the R is built in /root/dls/R-patched/bin instead of
/usr/lib/R/bin
 
 Did I miss something here?

Yes.

make install

-- 
   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@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Learning, if and else

2005-06-13 Thread Paulo Brando

Dear Rs,

I have tried to use conditional expressions to calculate biomass for
different life forms (trees, lianas, and palms).

Here is an example:

 lifeform

dbh  form
1   30  tree
2   29  tree
3   28  tree
4   27  tree
5   26  tree
6   25  tree
7   24  tree
8   23  tree
9   22  tree
10  21  tree
11  20  tree
12  15 liana
13  14 liana
14  13 liana
15  12 liana
16  11 liana
17  10 liana
18   9 liana
19   8 liana
20   7 liana
21   6 liana
22   5 liana
23  30  palm
24  29  palm
25  28  palm
26  27  palm
27  26  palm
28  25  palm
29  24  palm
30  23  palm
31  22  palm
32  21  palm
33  20  palm

### I want to include biomass 

lifeform$biomass - 

{
  if(lifeform$form==tree)
   exp(-4.898+4.512*log(dbh)-0.319*(log(dbh))^2) 
   else{ 
if (lifeform$form==liana)
   10^(0.07 + 2.17 * log10 (dbh))
   else (NA)
}
Warning message:
the condition has length  1 and only the first element will be used in:
if (lifeform$form == tree) exp(-4.898 + 4.512 * log(dbh) -


### But I always get the message warning message above. 



I looked for similar examples in R mail list archive, but they did not
help a lot.

I am quite new to 'R'. Any material that covers this theme?

Thank you very much!

Paulo

PS. Sorry about the last e-mail. I did not change the message title.

Paulo M. Brando
Instituto de Pesquisa Ambiental da Amazonia (IPAM)
Santarem, PA, Brasil.
Av. Rui Barbosa, 136.
Fone: + 55 93 522 55 38
www.ipam.org.br
E-mail: [EMAIL PROTECTED]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] aggregate and stack

2005-05-25 Thread Paulo Brando
Dear All,

I have tried to calculate tree mean growth but I think the structure I used 
below (growthresumo) is not the most elegant, even though it worked. The only 
problem I had in this first part was that  I cannot use 'summary', just 'mean' 
(sorry but 'R' is pretty new for me).

growthresumo - 
aggregate(growth[,c(16,19,23,27,31,35,39,43,47,52,56,60,64,68,72,76,81,85,89,93,97,101,105,109,113,117,121,125,129,133,137,
141,145,149,153,157,161,165,169,173,177,181,185,189,194,197,201,205,209,213,217,221,225,229,233,237,241)],
by=(growth[,c(3,8)]),MEAN,na.rm=TRUE)

#after growth is calculated, I want to stack the results in just one colunm.  

growthvertical - c(growthresumo[,3],...,growthresumo[,50]) # this is very 
time consuming though

Parcel - c(C9,S8...C9,S8) # 50 items

date  c(DATE1DATE50)

growthpermonth - data.frame(Parcel, Date, growthvertical)

Thank you very much!

Paulo

Paulo Brando
Inst. de Pesquisa Ambiental da Amazônia (IPAM)
Rua Rui Barbosa,136.
68.005.080 Santarém, PA, Brasil.
Fone/Fax ++ 55 93 522 5538
www.ipam.org.br
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


[R] Basic matematical functions with NAs

2005-05-24 Thread Paulo Brando
Dear All,

I've tried to sum columns -- different species of flowers, fruits plus twigs -- 
with NAs to get litterfall/trap, and then after use litterfall to calculate 
production (litterfall (grams)/ hectare/ day. But R 'sees' litterfall/trap as a 
string. 

My question: How to use basic mathematical functions to deal with NAs in data 
management. 

Example (as you can note I have many missing values -- no fruit  fell in the 
trap.


  area ponto date pseco psaco pliquido florg1 flor1 florg2 flor2 florg3 
flor3 frutog1 fruto1 frutog2 fruto2 frutog3 fruto3 frutog4 fruto4 frutog5 
fruto5 frutog6 fruto6 frutog7 fruto7 frutog8 fruto8 twigs  
  A A 1 38233 17.7 1.6 7.1 0.266 1   
  A AA 1 38233 12.5 8.7 3.8 
  A AB 1 38233 13.9 1.7 3.2   0.421 3 
  A B 1 38233 12.1 1.6 1.5   0.248 2 0.435 7 0.16 1 
  A BORDA 1 38233
  A C 1 38233 15.6 1.7 4.9   0.374 2 0.298 3 0.231 1 
  A F 1 38233 14 1.5 3.5 0.366 45 0.153 1 0.15 1   



Paulo Brando
Inst. de Pesquisa Ambiental da Amazônia (IPAM)
Rua Rui Barbosa,136.
68.005.080 Santarém, PA, Brazil.
Fone/Fax ++ 55 93 522 5538
www.ipam.org.br
[[alternative HTML version deleted]]

__
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html