Re: [R] Calculating plotting a linear regression between two correlated variables

2012-01-23 Thread B77S
I know this isn't what you are asking, but have you considered examining the
relationship between dA and the community density excluding dA?


JulieV wrote
 
 Hi Josh,
 
 Thanks for your response ! 
 
 Actually, I already tried to plot it with a classical regression and I
 know the relation is linear:
 
 dA = 0.765 * dCOM - 0.089 
 p(slope)  0.0001 
 p(intercept) = 0.0003
 
 The fact is that I can not use these results as my variables dA and dCOM
 are correlated (as mentioned above, Eq.1). What I need to find out is
 which correction I should do on my data, and how, to be able to calculte
 the regression p-values correctly with Linear Mixed Models.
 
 I am interested in this because I know that my species decline at
 different rates when my community is declining. 
 For example, with decreasing values of dCOM, dA reaches 0 before dB.
 
 
 Julie
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Calculating-plotting-a-linear-regression-between-two-correlated-variables-tp4319051p4321222.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] R not giving significance tests for coefficients/estimates?

2012-01-23 Thread B77S
 3x4
Error: unexpected symbol in 3x4

R has no idea that you equate x as multiplication.. use an astrix

 3*4
[1] 12




dominic wrote
 
 This is basically my code: 
 
 library(MASS)
 lmsreg(formula = b0 ~ b1 + b3 + b1xb2, data=mydata) 
 
 b1xb2 is an interaction but it was the centered value for a continuous
 variable times a categorical variable. 
 
 I am used to using Mplus statistical software and SAS for robust
 regression, and they'll usually give you a t-test, p-value as well as the
 SE and/or CI. But I am not getting it here even though I have sent that is
 the correct code to get it on some websites that have posted their output.
 I
 
 I have also tried: 
 
  library(MASS)
  lqs(formula = b0 ~ b1 + b3 + b1xb2, data=mydata,
 + method = c(lqs))
 
 And rlm(formula ...) too, but neither provide tests of significance. 
 
 Am I doing something wrong? Any help on this matter is greatly
 appreciated. 
 
 Thanks, 
 
 Dominic
 


--
View this message in context: 
http://r.789695.n4.nabble.com/R-not-giving-significance-tests-for-coefficients-estimates-tp4321669p4321876.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] Automated Regressions

2011-12-12 Thread B77S
I don't know why you had c in a(1:2000))  
c is a function see ?c ...
and you want a (the row number in SQL_Code) to change with each iteration
in the loop.


Perhaps this might work (I'm not saying this is the best option, just a
potential fix for what you have): 

for (a in 1:2000) {
Dataset - sqlQuery(Database, SQL_Code[a,1])
print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
}







ryanSt wrote
 
 Hello R-Experts,
 
 I've got a question, concerning the automation of a number of regressions
 (lm) with the help of a loop (for i in ).
 
 The situation is as follows (the code follows after that):
 I have my data in an access database. I have historical data for 2000
 parts, for each of this parts I want to do a regression analysis, so I
 need to do 2000 regressions (just for one country, there are also more
 countries). So this would be a lot of manual effort. 
 What I want to do is to automate this routine. I have already established
 a database connection via RODBC.
 So I can acces every part with its distinct code by a SQL Query. For every
 part, the SQL Query has to be adapted for the parts name.
 My idea was to generate the SQL Code in Excel for ervery part and save
 this as an txt-file. So I can define the SQL-Codes as an object (SQL_Code
 - load.table(...txt, header = FALSE). 
 In the next step I can build a loop, which tells R to go through the
 object SQL_Code line for line, using the text for the SQL Query.
 
 
 The code is as follows:
 SQL Code in the sqlparts.txt. file: SELECT table.* FROM table WHERE
 ((table.part) = '2929AAD766') (2000 lines for all parts, each part has a
 distinct code)
 
 SQL_Code - load.table(sqlparts.txt, header = FALSE)
 
 Loop: 
 for (c in a(1:2000)) {
 
 Dataset - sqlQuery(Database, SQL_Code[a,1])
 
 print(summary(lm(Quant~ UPE + Mon, data = Dataset)))
 }
 
 
 Unfortunately, this loop doesn't work. I think, it's because R does not
 interpret the object SQL_Code as text, so the sqlQuery is incomplete.
 
 Can anybody help me with that problem?
 
 Thank you in advance.
 
 Greets
 Ryan
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Automated-Regressions-tp4186280p4187109.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 with study guide for R exam

2011-12-09 Thread B77S
343GS

You should consider dropping out of college; I don't think you belong there.
McDonalds is hiring.



343GS wrote
 
 Thanks for nothing, jerk! DENMARK IS POO
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-study-guide-for-R-exam-tp4173951p4178139.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] profile likelihood

2011-12-08 Thread B77S
Try posting this question at least 1 more time.  



plocq wrote
 
 Hi,
 
 I try to use the function profile() of the SpatialExtremes' package to
 obtain the profile likelihood of parameters for an extreme values fit
 based on Poisson process :
 
 fit-fpot(data, threshold, model=pp, npp=365).
 
 But when I call profile(fit), I obtain the following error (even if I
 precise others arguments of the function) :
 
 [1] profiling loc
 Erreur dans nlpot(p[1], p[2], ...) :
 argument(s) inutilisé(s) (loc = 9.58435562072)
 
 
 I don't understand what is unused and why. From where does this error come
 from? If someone could help me it would be nice...!
 


--
View this message in context: 
http://r.789695.n4.nabble.com/profile-likelihood-tp4174090p4175254.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] Problem with xlsx package

2011-12-07 Thread B77S
If all else fails, open it in Excel... save as .csv

read.csv()




Nikhil Joshi wrote
 
 I am trying to read an xlsx spreadsheet (1506 rows, 501columns) all
 populated but getting the following error:
 Please advise as to how to get around this issue.
 
 res - read.xlsx(c:\\BSE_v2.xlsx,1)
 Error in .jcall(RJavaTools, Ljava/lang/Object;, invokeMethod, cl,  :
   java.lang.OutOfMemoryError: Java heap space
 
 Here is the session info:
 
 sessionInfo()
 R version 2.12.1 (2010-12-16)
 Platform: i386-pc-mingw32/i386 (32-bit)
 
 locale:
 [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
 States.1252
 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
 
 [5] LC_TIME=English_United States.1252
 
 attached base packages:
 [1] grid  stats graphics  grDevices utils datasets  methods
 base
 
 other attached packages:
  [1] xlsx_0.2.4   xlsxjars_0.2.0   rJava_0.8-8
 
  [4] quantmod_0.3-15  TTR_0.20-2
 Defaults_1.1-1
  [7] urca_1.2-4   RBGL_1.26.0 
 graph_1.28.0
 
 [10] colorspace_1.0-1 spatstat_1.21-4 
 deldir_0.0-13
 
 [13] mgcv_1.7-2   reshape_0.8.4plyr_1.4
 
 [16] fExtremes_2100.77fTrading_2100.76
 fGarch_2110.80
 [19] fBasics_2110.79  timeSeries_2130.90
 timeDate_2130.91
 [22] mc2d_0.1-9   mvtnorm_0.9-96
 mixtools_0.4.4
 [25] boot_1.2-43  MASS_7.3-9
 SuppDists_1.1-8
 [28] ghyp_1.5.4   gplots_2.8.0
 caTools_1.11
 
 [31] bitops_1.0-4.1   gdata_2.8.1 
 gtools_2.6.2
 
 [34] numDeriv_2010.11-1   xtable_1.5-6
 PerformanceAnalytics_1.0.3.2
 [37] sn_0.4-16mnormt_1.4-0 xts_0.7-5
 
 [40] zoo_1.6-4RODBC_1.3-2
 
 loaded via a namespace (and not attached):
 [1] lattice_0.19-13Matrix_0.999375-46 nlme_3.1-97tools_2.12.1
 
   [[alternative HTML version deleted]]
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Problem-with-xlsx-package-tp3298470p4169793.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] similarity matrix

2011-12-05 Thread B77S
That really all depends on what you need; and I can't tell you what you need. 



set wrote
 
 I'm sorry, I made a mistake in my example. you're right. I don't really
 know how a similarity alogrithm worksbut I'm willing to try that...are
 there any good examples available?
 Thank you
 


--
View this message in context: 
http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4160902.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] Why can't I figure this out? :S

2011-12-05 Thread B77S
Why can't you figure this out?
I think you already know the answer:   I don't speak computer. 

Time to learn, or get another job I suppose.  I hope you at least speak
math-statistics if you are going to attempt to understand this.

The only way you are going to be able to figure that code out is to break it
up into pieces until you DO understand it.  If that is too much work for
you, then   

Good luck.



Jasmine007 wrote
 
 Hi, so I don't speak computer and I have no idea what this code is telling
 the program to do, but I apparently need to be able to find and isolate
 influencial observations. Problem, I have no idea what the error means and
 where it may be from in the code.
 
 error I get is below the code
 
 {
 ## OLS results
 NameC- lm(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy)
 
 ## default: choose psamp = quantile
 n - length(residuals(NameC))
 k - length(coef(NameC))
 if(is.null(quantile)) quantile - c(floor((n + k + 1)/2),
 floor((n + k)/2))
 quantile - rep(quantile, length.out = 2)
 if(is.null(psamp)) psamp - quantile[1]
 
 ## LTS results with robust residuals
 NameC_lts -
 lqs(gpanew~female+female:lastinit+agenew+canadian+mom_ed+yearstudy,
 quantile = quantile[1], psamp = psamp, nsamp = nsamp)
 rr - residuals(NameC_lts)/NameC_lts$scale[2]
 rr_nok - abs(rr)  critval[1]
 ## robust leverage via MCD (or MVE)
 X - model.matrix(NameC)[,-1]
 cv - cov.rob(X, method = method,
 quantile = quantile[2], nsamp = dist_nsamp)
 rd - sqrt(mahalanobis(X, cv$center, cv$cov))
 rd_nok - rd  critval[2]
 ## ROBUST results
 nok - rr_nok  rd_nok
 NameC_rob - lm(formula, data[!nok,])
 rval - list(ols = NameC, lts = NameC_lts, robust = NameC_rob,
 cov.rob = cv, robresid = rr, robdist = rd,
 high_residuals = rr[rr_nok], high_leverage = rd[rd_nok],
 bad_leverage = nok, psamp = psamp, method = method,
 nsamp = list(lts = nsamp, dist = dist_nsamp),
 quantile = list(lts = quantile[1], dist = quantile[2]))
 return(rval)
 }
 
 Error: object of type 'closure' is not subsettable
 
 Any ideas, In plain non-computer language.. I have a headache from trying
 to figure out if this question had been answered before.
 
 Thank you
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Why-can-t-I-figure-this-out-S-tp4162826p4163150.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] frequency table?

2011-12-05 Thread B77S
Set,

This is the same post as your Similarity Matrix post.

I'm not trying to be a smart ass here, but ... ?Can you fit a square peg in
a round hole?... yes, but it doesn't mean it belongs there.  

I suggest you get a piece of paper and a pencil and figure out 1) what you
are trying to do and why, and 2) how you would do that by hand.  After you
do that, you should be able to figure this out on your own or formulate a
question to post that someone will be able to answer.  Reading might help as
well.



set wrote
 
 Hello R-users,
 
 I've got a file with individuals as colums and the clusters where they
 occur in as rows. And I wanted a table which tells me how many times each
 individual occurs with another. I don't really know how such a table is
 called...it is not a frequency tableMy eventual goal is to make
 Venn-diagrams from the occurence of my individuals.
 
 So I've this:
 
 cluster   ind1 ind2 ind3 etc.
 10  1 2
 23   01
 31   1 1
 
 And I want to go to this:
 ind1  ind2  ind3
 ind1  0  42
 ind2  4  04
 ind3  2   4   1
 
 is there a way to do this?
 Thank you for your help
 


--
View this message in context: 
http://r.789695.n4.nabble.com/frequency-table-tp4156422p4163192.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] Programming Statistical Functions

2011-12-04 Thread B77S
As Stephen pointed out, this is easy to do.  The word file the OP posted has
all the necessary formulae.  Now you just need to learn how to convert those
formulae into R functions
Stephen gave you an example of how to create a function for CV.  Now run
with it.

perhaps something like this is what you need:

http://cran.r-project.org/doc/contrib/Short-refcard.pdf

It is time for you to do some reading on your own.

Good luck.



gvjones wrote
 
 Hello,
 
 Did you find anything helpful for calculating the statistical functions in
 your list. I would like to also calculate these and have been looking for
 some code to do so.
 
 Thanks
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Programming-Statistical-Functions-tp2307880p4157101.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] problem merging data with different shapes

2011-12-04 Thread B77S
Please use dput() to post your example data sets.

dput(Adata)
dput(Bdata)

**then copy and paste the results of each so that we can play around with
it easily.




Miriam -2 wrote
 
 I have been trying to merge datasets, one of which has a long format
 (Adata) and one has a (different) long format (Bdata):
 
 Adata  Bdata
 subject order bpm  subject order trial agegroup gender
 1 1   70.21  1 3   2   1
 1 1   69.51  2 1   2   1
 1 1   68.81  3 2   2   1
 1 2   69.12  1 2   1   2
 1 270 2  2 3   1   2
 1 2   70.52  3 1   1   2
 1 3   70.2...
 1 3
 1 3
 2 1 
 2 1 
 ...   ...
 
 In the end I would like to have a dataset that contains A unchanged with
 the additional information from B added.
 
 subject order bpm trial agegroup gender
 1 1   70.2  3   2   1
 1 1   69.5  3   2   1
 1 1   68.8  3   2   1
 ...  
 I have tried:
 newdataframe - merge(Adata,Bdata, by= c(subject, order), sort =
 FALSE)
 
 For some reason, the trial column is not matched to the subject and order
 information, despite them being identified as key-variables for the merge.
 (The same is true for other variables, the actual dataset has more
 variables and trials, but this is essentially the problem.)
 So it results in something like:
 subject order bpm trial agegroup gender
 1 1   70.2  3   2   1
 1 1   69.5  2   2   1
 1 1   68.8  1   2   1 
 
 What could be my mistake?
 
 Thank you VERY much.
 Miriam
 
 
 -- 
 
 
 
 
 --
 
 __
 R-help@ 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://r.789695.n4.nabble.com/problem-merging-data-with-different-shapes-tp4157137p4157442.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] Export cols to single csv files

2011-12-04 Thread B77S
just use indexing.
without doing it all for you...

df - structure(list(AA = c(0.3, 0.1, 0.6), BB = c(0.9, 0.4, 0.2), 
CC = c(1, 0.8, 0.6), DD = c(0.7, 0.5, 0.5)), .Names = c(AA, 
BB, CC, DD), class = data.frame, row.names = c(NA, -3L
))

write.csv(df[,1], paste(colnames(df[1]), csv, sep=.))




Chega wrote
 
 Hi
 
 I am trying to batch export the columns of a numeric matrix to separate
 csv files by naming them according to the column names.
 
 So my matrix in R looks like this:
  AA   BB   CC   DD   etc.
 1:  0.3  0.9  1.0   0.7  ...
 2:  0.1  0.4  0.8   0.5  ...
 3:  0.6  0.2  0.6   0.5  ...
 etc. 
 
 Now I am looking for a way to get these files (file names in quotes):
 
 AA.csv  BB.csv CC.csvetc.
 1:  0.31: 0.91: 1.0
 2:  0.12: 0.42: 0.8 
 3:  0.63: 0.23: 0.6
 etc.   etc.   etc.
 
 As I understand this may be done using write.csv and a loop with the
 column names, but I have no idea how to export single columns.
 
 Thanks i.a. for help!
 Chega
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Export-cols-to-single-csv-files-tp4157484p4157537.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] similarity matrix

2011-12-04 Thread B77S
I apologize to the list and you if I am mis-understanding something, but...

As an example:
ind2 occurs with ind1 only in cluster#3, so why does it get a value of 4 in
your similarity matrix?

Also, if this isn't a recognized similarity algorithm, perhaps you should at
the very least put quotes around similarity.  

Again, sorry if I am confused here.
 


set wrote
 
 Hello R-users,
 
 I've got a file with individuals as colums and the clusters where they
 occur in as rows. And I wanted a similarity matrix which tells me how many
 times each individual occurs with another. My eventual goal is to make
 Venn-diagrams from the occurence of my individuals.
 
 So I've this:
 
 cluster   ind1 ind2 ind3 etc.
 10  1 2
 23   01
 31   1 1
 
 And I want to go to this:
 ind1  ind2  ind3
 ind1  0  42
 ind2  4  04
 ind3  2   4   1
 
 is there a way to do this?
 Thank you for your help
 


--
View this message in context: 
http://r.789695.n4.nabble.com/similarity-matrix-tp4157576p4157840.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] Iteration in R

2011-12-03 Thread B77S
Hi Michael, 
How would you do this with lapply to return a list?
I can't seem to get that to work (I haven't used these much and am trying to
learn).
Thanks
Brad


Michael Weylandt wrote
 
 ? replicate
 
 or a for loop
 
 or do all one hundred simulations at once
 
 x - matrix(rnorm(100^2, 1, 2), 100)
 
 It's going to depend on what you want to do with the numbers.
 
 Michael
 
 On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt; wrote:
 Hi,
 I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
 2.0) one hundred times in R but I don't seem to have a clue.
 Can anyone help?
 Your help is very much appreciated.

 Martin

        [[alternative HTML version deleted]]


 __
 R-help@ 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@ 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://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.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] Iteration in R

2011-12-03 Thread B77S
Interesting and thank you; I'm confused as to why this doesn't work with: 

lapply(rep(1,6), FUN=rnorm, n=10, mean=1.0, sd=1) 



andrija djurovic wrote
 
 Hi Brad. Maybe something like this:
 
 lapply(rep(1,6), function(x) rnorm(10,0,1))
 
 Andrija
 
 On Sat, Dec 3, 2011 at 8:21 PM, B77S lt;bps0002@gt; wrote:
 
 Hi Michael,
 How would you do this with lapply to return a list?
 I can't seem to get that to work (I haven't used these much and am trying
 to
 learn).
 Thanks
 Brad


 Michael Weylandt wrote
 
  ? replicate
 
  or a for loop
 
  or do all one hundred simulations at once
 
  x - matrix(rnorm(100^2, 1, 2), 100)
 
  It's going to depend on what you want to do with the numbers.
 
  Michael
 
  On Sat, Dec 3, 2011 at 1:10 PM, Martin Zonyrah lt;martin2005z@gt;
 wrote:
  Hi,
  I need help. I am trying to iterate this command  x - rnorm(100, 1.0,
  2.0) one hundred times in R but I don't seem to have a clue.
  Can anyone help?
  Your help is very much appreciated.
 
  Martin
 
 [[alternative HTML version deleted]]
 
 
  __
  R-help@ 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@ 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://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154479.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@ 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@ 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://r.789695.n4.nabble.com/Iteration-in-R-tp4154433p4154559.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] Moving column averaging

2011-12-03 Thread B77S
I don't know the answer, but would suppose not.
You could test this for yourself using:
system.time()
example: 
system.time(rnorm(10,0,1)) 


Chega wrote
 
 This solved my problem - Thanks a lot for your help! Please allow me one
 more question: Works zoo's rollapply on a plain matrix faster than on a
 zoo object? I am asking since I wanted to apply the provided averaging
 code to a larger matrix (2500 rows x 200 cols), which is quite time
 consuming...
 
 Thanks again!
 
 Chega
 
 
 From: B77S [via R] lt;ml-node+s789695n4143909h3@.nabblegt;
 To: Chega lt;chegaga@gt; 
 Sent: Friday, December 2, 2011 6:16 AM
 Subject: Re: Moving column averaging
 
 
 Sorry for that, and thanks Gabor, 
 I could have sworn that it wouldn't. 
 
 
 
 Gabor Grothendieck wrote
On Thu, Dec 1, 2011 at 7:13 PM, B77S [hidden email] wrote: 
 # need zoo to use rollapply() 
 
 # your data (I called df) 
 df - structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), 
    e = c(1L, 5L), f = c(4, 7)), .Names = c(a, b, c, d, 
 e, f), class = data.frame, row.names = c(NA, -2L)) 
 
 # transpose and make a zoo object 
 df2 - zoo(t(df)) 
 
 #rollapply to get means and transpose back 
 means - t(rollapply(df2, width=2, by=2, FUN=mean)) 
 
 # adding the combined column names you requested 
 colnames(means) - apply(matrix(names(df), nrow=2), 2, paste,
 collapse=, ) 
 

Note that zoo's rollapply also works on plain matrices and vectors. 

-- 
Statistics  Software Consulting 
GKX Group, GKX Associates Inc. 
tel: 1-877-GKX-GROUP 
email: ggrothendieck at gmail.com 

__ 
[hidden email] 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. 
 
 
 
 If you reply to this email, your message will be added to the discussion
 below:
 http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143909.html
 To unsubscribe from Moving column averaging, click here.
 NAML
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4154770.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] Data Analysis for Gas Prices

2011-12-03 Thread B77S
use a  ?  to get help on a function; example:

?read.table

If you do this you will see an option called header...  
use header=T if your top row contains column names.  

Learn how to read these help pages.  Also, read thru a few beginner R
manuals and see this website:
http://www.statmethods.net/interface/io.html

As for the rest of your questions. 
Perhaps this is your sign to begin reading a intro-stats book, or inquire on
a different forum.
see:
http://stats.stackexchange.com/questions

good luck


inferno846 wrote
 
 Hi there,
 
 I'm looking to analyze a set of data on local gas prices for a single day.
 I'm wondering what kind of questions I should be looking to ask and how to
 find and answer to them with R. Examples would be: 
 
 Do prices differ between brands?
 Does location affect (NE, NW, SE, SW) price?
 Does the number of nearby (within .25 miles) competitors affect price?
 Do gas stations near shopping centers or highways have different prices?
 
 Also, could anyone help me figure out how to import a data table to R?
 When I try to create a .txt file from a word document and read it in R,
 the format of the first column always messes up. Any/all help is
 appreciated.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Data-Analysis-for-Gas-Prices-tp4155078p4155185.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] How to test for Poisson?

2011-12-02 Thread B77S
A simple way to determine if it is NOT is to see if the mean (the single
parameter of a poisson: lambda) and variance are the same. 

This really has nothing to do with R (other than the data source), and since
it is homework, you will likely get no further help here.
Good luck.


RToss wrote
 
 Hi!
 
 I am sitting with a school assignment, but I got stuck on this one.
 I am suppose to test if my data is Poisson-distributed.
 The data I´m using is the studie Bids, found in the Ecdat-package, and
 the variable of interest is the dependent numbids.
 How do I practically perform a test for this?
 
 Kind regards/ Richard
 


--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-test-for-Poisson-tp4147356p4147519.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] Summarizing elements of a list

2011-12-01 Thread B77S
Someone is bound to know a better way, but...

subset(unlist(Version1_), subset=names(unlist(Version1_))==First)






LCOG1 wrote
 
 Hi everyone, 
I looked around the list for a while but couldn't find a solution to my
 problem.  I am storing some results to a simulation in a list and for each
 element i have two separate vectors(is that what they are called, correct
 my vocab if necessary). See below
 
 Version1_-list()
 for(i in 1:5){
   Version1_[[i]]-list(First=rnorm(1),Second=rnorm(1))
 }
 
 What I want is to put all of the elements' 'First' vectors into a single
 list to box plot. But whats a more elegant solution to the below?
 
 c(Version1_[[1]]$First,Version1_[[2]]$First,Version1_[[3]]$First,Version1_[[4]]$First,Version1_[[5]]$First)
 
 since i have 50 or more simulations this is impractical and sloppy.  Do I
 need to store my data differently or is their a solution on the back end? 
 Thanks all.  
 
 Josh
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Summarizing-elements-of-a-list-tp4142479p4142884.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] Moving column averaging

2011-12-01 Thread B77S
# need zoo to use rollapply()

# your data (I called df)
df - structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L), 
e = c(1L, 5L), f = c(4, 7)), .Names = c(a, b, c, d, 
e, f), class = data.frame, row.names = c(NA, -2L))

# transpose and make a zoo object
df2 - zoo(t(df))

#rollapply to get means and transpose back
means - t(rollapply(df2, width=2, by=2, FUN=mean))

# adding the combined column names you requested
colnames(means) - apply(matrix(names(df), nrow=2), 2, paste, collapse=, ) 


HTH


--
View this message in context: 
http://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143329.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] calculate mean of multiple rows in a data frame

2011-12-01 Thread B77S


--
View this message in context: 
http://r.789695.n4.nabble.com/calculate-mean-of-multiple-rows-in-a-data-frame-tp4130468p4143875.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] Moving column averaging

2011-12-01 Thread B77S
Sorry for that, and thanks Gabor, 
I could have sworn that it wouldn't.



Gabor Grothendieck wrote
 
 On Thu, Dec 1, 2011 at 7:13 PM, B77S lt;bps0002@gt; wrote:
 # need zoo to use rollapply()

 # your data (I called df)
 df - structure(list(a = 1:2, b = 2:3, c = c(5L, 9L), d = c(9L, 6L),
    e = c(1L, 5L), f = c(4, 7)), .Names = c(a, b, c, d,
 e, f), class = data.frame, row.names = c(NA, -2L))

 # transpose and make a zoo object
 df2 - zoo(t(df))

 #rollapply to get means and transpose back
 means - t(rollapply(df2, width=2, by=2, FUN=mean))

 # adding the combined column names you requested
 colnames(means) - apply(matrix(names(df), nrow=2), 2, paste, collapse=,
 )

 
 Note that zoo's rollapply also works on plain matrices and vectors.
 
 -- 
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.com
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Moving-column-averaging-tp4130179p4143909.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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?

2011-11-24 Thread B77S


--
View this message in context: 
http://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4104295.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] I cannot get species scores to plot with site scores in MDS when I use a distance matrix as input. Problems with NA's?

2011-11-24 Thread B77S
Try the daisy() function from the package cluster, it seems to be able to
handle NAs and non-dummy coded character variables

metaMDS(daisy(df, metric=gower))




Edwin Lebrija Trejos wrote
 
 Hi, First I should note I am relatively new to R so I would appreciate
 answers that take this into account.
  
 I am trying to perform an MDS ordination using the function “metaMDS” of
 the “vegan” package. I want to ordinate species according to a set of
 functional traits. “Species” here refers to “sites” in traditional
 vegetation analyses while “traits” here correspond to “species” in such
 analyses.  
  
 My data looks like this:
  
  Trait1   Trait2 Trait3  Trait4  Trait5  Trait…  
 Species1 228.44   16.56   1.66   13.22 1 short 
 Species2 150.55   28.07   0.41   0.60  1 mid
 Species3 NA   25.89 NA   0.55  0 large
 Species4 147.70   17.65   0.42   1.12 NA large
 Species… 132.68  NA   1.28   2.75  0 short
 
  
 Because the traits have different variable types, different measurement
 scales, and also missing values for some species, I have calculated the
 matrix of species distances using the Gower coefficient of similarity
 available in Package “FD” (which allows missing values). 
 My problem comes when I create a bi-plot of species and traits. As I have
 used a distance matrix in function “metaMDS” there are no species scores
 available. This is given as a warning in R: 
  
  NMDSgowdis- metaMDS(SpeciesGowdis)
 plot(NMDSgowdis, type = t)
 Warning message:In ordiplot(x, choices = choices, type = type, display =
 display, :Species scores not available” 
  
 I have read from internet resources that in principle I could obtain the
 trait (species) scores to plot them in the ordination but my attempts
 have been unsuccessful. I have tried using the function “wascores” in
 package vegan and “add.spec.scores” in package BiodiversityR. For this
 purpuse I have created a new species x traits table where factor traits
 were coded into dummy variables and all integer variables (including
 binary) were coerced to numeric variables. Here are the codes used and the
 error messages I have got: 
  
 “ NMDSgowdis- metaMDS(SpeciesGowdis)
 NMDSpoints-postMDS(NMDSgowdis$points,SpeciesGowdis)
 NMDSwasc-wascores(NMDSpoints,TraitsNMDSdummies)
 Error in if (any(w  0) || sum(w) == 0) stop(weights must be non-negative
 and not all zero) : missing value where TRUE/FALSE needed” 
  
 I imagine the problem is with the NA’s in the data. 
 Alternatively, I have used the “add.spec.scores” function,
 method=”cor.scores”, found in package BiodiversityR. This seemed to work,
 as I got no error message, but the species scores were not returned. Here
 the R code and results:
 “
 A-add.spec.scores(ordi=NMDSgowdis,comm=TraitsNMDSdummies,method=cor.scores,multi=1,
 Rscale=F,scaling=1)
 plot(A)
 Warning message:In ordiplot(x, choices = choices, type = type, display =
 display, :Species scores not available“
  
 Can anyone guide me to get the trait (“species”) scores to plot together
 with my species (“site”) scores?
 Thanks in advance,
 Edwin
 
 
 __
 R-help@ 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://r.789695.n4.nabble.com/I-cannot-get-species-scores-to-plot-with-site-scores-in-MDS-when-I-use-a-distance-matrix-as-input-Pr-tp4103699p4104406.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] Looping and paste

2011-11-23 Thread B77S
out - vector(list)
Ylab - for(i in 1:length(BndY))
{ 
out[i] - paste(BndY[i], to ,BndY[i],mN)
} 

Ylab - do.call(c, out)






markm0705 wrote
 
 Dear R helpers
 
 I'm trying to make up some labels for plot from this vector
 
 BndY-seq(from = 18900,to= 19700, by = 50)
 
 using
 
 Ylab-for(i in BndY) {c((paste(i, to ,i+50,mN)))}
 
 but the vector created is NULL
 
 However if i use
 
 for(i in BndY) {print(c(paste(i, to ,i+50,mN)))}
 
 I can see the for loop is making the labels I'm looking for but not sure
 on my error in assigning them to a vector
 
 Thanks in advance
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Looping-and-paste-tp4101892p4102066.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] Removing rows in dataframe w'o duplicated values

2011-11-22 Thread B77S
This is ugly, but it gets what you want. 

dat[which(dat[,1] %in% unique((dat[duplicated(dat[,1], fromLast = T),
1]))),]






AC Del Re wrote
 
 Hi,
 
 Is there an easy way to remove dataframe rows without duplicated values of
 a specified column ('id')?  e.g.,
 
 dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 =
 c(1,4,3,3,4,3))
 dat
 
   id value value2
 1  1 5  1
 2  1 6  4
 3  1 7  3
 4  2 4  3
 5  3 5  4
 6  3 4  3
 
 
 This is sample data and the real data has hundreds of rows. In this
 case, only row 4 does not have a duplicated id and I would like to
 remove it without using:
 
 
 dat$id[4] - NULL
 
 
 Any help is appreciated!
 
 
 AC
 
   [[alternative HTML version deleted]]
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Removing-rows-in-dataframe-w-o-duplicated-values-tp4096582p4096672.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] return only pairwise correlations greater than given value

2011-11-17 Thread B77S
This is probably not the prettiest or most efficient function ever, but this
seems to do what I wanted.


spec.cor - function(dat, r, ...){

require(reshape)

d1 - data.frame(cor(dat))
d2 - melt(d1)
d2[,3] - rep(rownames(d1), nrow(d2)/length(unique(d2[,1])))
d2 - d2[,c(variable, V3, value)]
colnames(d2) - c(V1, V2, value)
d2 - d2[with(d2, which(V1 != V2, arr.ind=T)), ]
d2 - d2[which(d2[,3] =r | d2[,3] = -r, arr.ind=T),]
d2[,1:2] - t(apply(d2[,1:2], MARGIN=1, function(x) sort(x)))
d2 - unique(d2)

return(d2)
}



data(mtcars)


 spec.cor(mtcars[,2:5], .6)
Using  as id variables
V1   V2  value
2  cyl disp  0.9020329
3  cyl   hp  0.8324475
4  cyl drat -0.6999381
7 disp   hp  0.7909486
8 disp drat -0.7102139



I'm not sure how to make melt() quit giving the Using  as id variables
warning, but I don't really care either.






B77S wrote:
 
 Thanks Michael, 
 
 I just started on the following code (below), and realized I should ask,
 as this likely exists already. 
 
 basically what I'd like is for the function to return (basically) what you
 just suggested, plus the names of the two variables (I suppose pasted
 together would be good). 
 
 I hope that is clear, and obviously I didn't get so far as to add the
 names to the output.
 
 # 
 sig.cor - function(dat, r, ...){
 
 cv2 - data.frame(cor(dat))
 var.names - rownames(cv2)
 
 list.cv2 - which(cv2 =r | cv2 = -r, arr.ind=T)
 cor.r - cv2[list.cv2[which(list.cv2 [,row]!=list.cv2 [,col]),]]
 cor.names - var.names[list.cv2[which(list.cv2 [,row]!=list.cv2
 [,col]),]]
 
   
 return(cor.r)
 
 }
 
 
 data(mtcars)
 sig.cor(mtcars[,2:5], .90)
 
 
 # sig.cor(mtcars[,2:5], .90)
 #[1] 0.9020329 0.9020329
 
 
 # Ideally this would look likt this:
 
 cyl-disp
 0.9020329
 
 
 
 
 
 
 Michael Weylandt wrote:
 
 What exactly do you mean returns them? More generally I suppose,
 what do you have in mind to do with this?
 
 You could do something like this:
 
 BigCorrelation - function(X){
 
  return(which(abs(cor(X))  0.9, arr.ind = T))
 }
 
 but it hardly seems worth its own function call.
 
 On Thu, Nov 17, 2011 at 12:42 AM, B77S lt;bps0002@gt; wrote:
 Hello,

  I would like to find out if a function already exists that returns only
 pairwise correlations above/below a certain threshold (e.g, -.90, .90)

 Thank you.



 --
 View this message in context:
 http://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079028.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@ 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@ 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://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4081534.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] return only pairwise correlations greater than given value

2011-11-17 Thread B77S
Excellent; thanks Josh.


Joshua Wiley-2 wrote:
 
 Hi Brad,
 
 You do not really need to reshape the correlation matrix.  This seems
 to do what you want:
 
 spec.cor - function(dat, r, ...) {
   x - cor(dat, ...)
   x[upper.tri(x, TRUE)] - NA
   i - which(abs(x) = r, arr.ind = TRUE)
   data.frame(matrix(colnames(x)[as.vector(i)], ncol = 2), value = x[i])
 }
 
 spec.cor(mtcars[, 2:5], .6)
 
 Cheers,
 
 Josh
 
 On Wed, Nov 16, 2011 at 9:58 PM, B77S lt;bps0002@gt; wrote:
 Thanks Michael,

 I just started on the following code (below), and realized I should as as
 this might exist.

 basically what I'd like is for the function to return (basically) what
 you
 just suggested, plus the names of the two variables (I suppose pasted
 together would be good).

 I hope that is clear.

 #
 sig.cor - function(dat, r, ...){

 cv2 - data.frame(cor(dat))
 var.names - rownames(cv2)

 list.cv2 - which(cv2 =r | cv2 = -r, arr.ind=T)
 cor.r - cv2[list.cv2[which(list.cv2 [,row]!=list.cv2 [,col]),]]
 cor.names - var.names[list.cv2[which(list.cv2 [,row]!=list.cv2
 [,col]),]]


 return(cor.r)

 }





 Michael Weylandt wrote:

 What exactly do you mean returns them? More generally I suppose,
 what do you have in mind to do with this?

 You could do something like this:

 BigCorrelation - function(X){

      return(which(abs(cor(X))  0.9, arr.ind = T))
 }

 but it hardly seems worth its own function call.

 On Thu, Nov 17, 2011 at 12:42 AM, B77S lt;bps0002@gt; wrote:
 Hello,

  I would like to find out if a function already exists that returns
 only
 pairwise correlations above/below a certain threshold (e.g, -.90, .90)

 Thank you.



 --
 View this message in context:
 http://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079028.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@ 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@ 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://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079044.html
 Sent from the R help mailing list archive at Nabble.com.

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

 
 
 
 -- 
 Joshua Wiley
 Ph.D. Student, Health Psychology
 Programmer Analyst II, ATS Statistical Consulting Group
 University of California, Los Angeles
 https://joshuawiley.com/
 
 __
 R-help@ 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://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4081643.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] R forum for only Statistics

2011-11-16 Thread B77S
In addition to getting help from others, I always find that seeking answers
through reading to be helpful.  I would suggest a basic stats book and this
paper regarding issues indices like species richness:


http://www.amazon.com/Primer-Ecological-Statistics-Nicholas-Gotelli/dp/0878932690


Here is one you should probably read as well: 


http://onlinelibrary.wiley.com/doi/10.1046/j.1461-0248.2001.00230.x/full


Happy reading.





geeknick wrote:
 
 Hi there I need some 
 http://calculate-conditional-and-distributio.blogspot.com/2011/11/blog-post.html
 Statistics Help !! What statistical tests should i use/consider
 (pref in SPSS) in regards to an invertebrate survey i have carried out
 comparing urban street trees to urban park trees. I am looking at species
 richness and abundance between the two sites and also other variables such
 as tree species, tree width at base, distance from road/tarmac, tree base
 substrate and weather at time of collection. any help would be greatly
 appreciated! i tried on this link and i found this blog very
 usefull.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/R-forum-for-only-Statistics-tp3480715p4076599.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] return only pairwise correlations greater than given value

2011-11-16 Thread B77S
Hello, 

 I would like to find out if a function already exists that returns only
pairwise correlations above/below a certain threshold (e.g, -.90, .90)

Thank you. 



--
View this message in context: 
http://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079028.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] split list of characters in groups of 2

2011-11-16 Thread B77S
hi, 

If i have a list of things, like this

var.names - c(a, b, c, d, e, f)

how can i get this:

a, b, c, d, e, f

thanks ahead of time. 
 

--
View this message in context: 
http://r.789695.n4.nabble.com/split-list-of-characters-in-groups-of-2-tp4079031p4079031.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] return only pairwise correlations greater than given value

2011-11-16 Thread B77S
Thanks Michael, 

I just started on the following code (below), and realized I should as as
this might exist. 

basically what I'd like is for the function to return (basically) what you
just suggested, plus the names of the two variables (I suppose pasted
together would be good). 

I hope that is clear.

# 
sig.cor - function(dat, r, ...){

cv2 - data.frame(cor(dat))
var.names - rownames(cv2)

list.cv2 - which(cv2 =r | cv2 = -r, arr.ind=T)
cor.r - cv2[list.cv2[which(list.cv2 [,row]!=list.cv2 [,col]),]]
cor.names - var.names[list.cv2[which(list.cv2 [,row]!=list.cv2
[,col]),]]


return(cor.r)

}





Michael Weylandt wrote:
 
 What exactly do you mean returns them? More generally I suppose,
 what do you have in mind to do with this?
 
 You could do something like this:
 
 BigCorrelation - function(X){
 
  return(which(abs(cor(X))  0.9, arr.ind = T))
 }
 
 but it hardly seems worth its own function call.
 
 On Thu, Nov 17, 2011 at 12:42 AM, B77S lt;bps0002@gt; wrote:
 Hello,

  I would like to find out if a function already exists that returns only
 pairwise correlations above/below a certain threshold (e.g, -.90, .90)

 Thank you.



 --
 View this message in context:
 http://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079028.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@ 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@ 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://r.789695.n4.nabble.com/return-only-pairwise-correlations-greater-than-given-value-tp4079028p4079044.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] pairs(), no axis labels/values for upper panel?

2011-11-15 Thread B77S
Steffen, 

Did you ever have luck getting rid of the tick marks?...  
I like your idea and have modified it, but yes, the tick marks need to go.



Steffen Fleischer wrote:
 
 Dear all,
 
 I want to draw a graph that contains the scatterplot matrix in the lower
 panel and coefficients in the upper panel. I used and adapted the example
 for the function pairs but cannot figure out how to get no values and
 ticks in the upper panel (the values should only be in the lower panel).
 The upper panel looks odd to me this way. Any hints?
 
 Thanks in advance
 Steffen
 
 
 Here is an example what the graph looks like:
 #
 data(mtcars)
 panel.cor - function(a, b, digits=2,  ...)
  {
  
   usr - par(usr); on.exit(par(usr))
  par(usr = c(0, 1, 0, 1))
  x-cbind(a,b)
  x-na.omit(x)
  n - nrow(x)
  pp - c(0.025, 0.975)
  corx - cor(x,method=s)[1, 2]
  CI-c(tanh(atanh(corx) + qnorm(pp)/sqrt((n - 3)/1.06)))
  txt1 - paste(rho =,format(c(corx, 0.123456789),
 digits=digits)[1])
  txt2-paste((,format(c(CI,0.123456789)[1],digits=digits),;
 ,format(c(CI,0.123456789)[2],digits=digits),),sep=)
  txt3-paste(N =,round(n,0))
  txt - paste(txt1,\n,95%KI ,txt2,\n,txt3, sep=)
  text(0.5, 0.5, txt,cex=.8)
  }

 diag.cor-function(a,b, ...)
 {
 usr - par(usr); on.exit(par(usr))
 par(usr = c(0, 1, 0,1))
 rect(0,0,1,1,col=grey)
  }
 
 pairs(mtcars[1:4],upper.panel=panel.cor,diag.panel=diag.cor,label.pos=0.5)
 #
 
 __
 R-help@ 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://r.789695.n4.nabble.com/pairs-no-axis-labels-values-for-upper-panel-tp3234437p4075283.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] multivariate modeling codes

2011-11-11 Thread B77S
Not sure if this helps, but did you try Google?

http://www.jstatsoft.org/v35/i09/paper

http://cran.r-project.org/web/packages/lcmm/lcmm.pdf

http://www.warwick.ac.uk/statsdept/useR-2011/abstracts/010411-liquetbenoit.pdf



yurirouge wrote:
 
 HI, 
 
 I am relatively new to R and would appreciate some help or directions for
 this. 
 I am trying to model 3 longitudinal outcomes jointly and to identify some
 predictors for these 3 joint outcomes (all continuous). I am trying to
 find some codes that I may modify to do this but cannot seem to find
 anything.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/multivariate-modeling-codes-tp4032624p4032643.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] Interpreting Multiple Linear Regression Summary

2011-11-09 Thread B77S
Please see ?dput

use dput(your data) and paste the output into a reply, thanks.

This way we know what you are working with. 




Rich Shepard wrote:
 
 I would appreciate pointers on what I should read to understand this
 output:
 
   summary(lm(TDS ~ Cond + Ca + Cl + Mg + Na + SO4))
 
 Call:
 lm(formula = TDS ~ Cond + Ca + Cl + Mg + Na + SO4)
 
 Residuals:
 ALL 1 residuals are 0: no residual degrees of freedom!
 
 Coefficients: (6 not defined because of singularities)
  Estimate Std. Error t value Pr(|t|)
 (Intercept)  125 NA  NA   NA
 Cond  NA NA  NA   NA
 CaNA NA  NA   NA
 ClNA NA  NA   NA
 MgNA NA  NA   NA
 NaNA NA  NA   NA
 SO4   NA NA  NA   NA
 
 Residual standard error: NaN on 0 degrees of freedom
(63 observations deleted due to missingness)
 
When I look at the summary for the data frame used for this model I do
 not
 see an excessive number of missing values or indications why there are no
 residual degrees of freedom. The same model applied to 8 other data frames
 did not produce similar results.
 
 Puzzled,
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Interpreting-Multiple-Linear-Regression-Summary-tp4020516p4020567.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] Interpreting Multiple Linear Regression Summary

2011-11-09 Thread B77S
There is only one row with a complete set of observations; I think lm() is
throwing out the rest.



Rich Shepard wrote:
 
 On Wed, 9 Nov 2011, John C Frain wrote:
 
 As far as I know if there is an NA in any variable in an observation the
 default is to drop the entire observation. Thus there are no observations
 in your calculation
 
 John,
 
Hadn't realized that. I know there are NA's in other data frames that
 yield model results. Perhaps it is the excessive numbers in this set that
 are the problem.
 
 Thanks,
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Interpreting-Multiple-Linear-Regression-Summary-tp4020516p4021352.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] Interpreting Multiple Linear Regression Summary

2011-11-09 Thread B77S
This is the output of dput(your data)


structure(list(Ca = c(NA, NA, 24.4, NA, 21.4, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 28, 32, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, 34.7, NA, 42.5, NA, 26, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 0.6, 21.4, NA, 48.3, 
63.5, NA, NA, 28.7, NA, NA, NA, NA, 64.3, 23), Cl = c(1.58, 5.6, 
3, NA, 1, 5, 1.2, 4, 4, 8.4, 1, 1.4, 4.9, 1.7, 2, 1.6, 3.3, 2.2, 
9, 1, 2, 1, 1, 5, 4, 3, 2.27, 1.76, 5.81, 4.23, 4.23, 6.25, 6.72, 
4, NA, 5, 5.8, 5.8, 2.2, 5.4, 5.4, 4.8, 8, 1, 4.8, 5.9, 5.9, 
13, 5.6, 1.2, NA, NA, NA, 3, 7, NA, NA, 2, NA, NA, NA, NA, 7, 
4.1), Cond = c(NA, NA, 190, 187, 184, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 248, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, 304, 354, 379, NA, 300, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, 2.2, 187, 285, 378, 533, 
207, 262, 244, 238, 280, 380, 402, 636, 300), Mg = c(NA, NA, 
10, NA, 9.1, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, 11, 12, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
17.4, NA, 21.1, NA, 24, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, 9.5, NA, 22.1, 29.9, NA, NA, 12.6, NA, NA, NA, NA, 
32.4, 21), Na = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 4L, 4L, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 
NA, NA, NA, NA, NA), SO4 = c(9.4, 6.5, 9, NA, 7, 55, 6.8, 105, 
15.6, 8.4, 8.8, 19.4, 37, 12, 10, 9.1, 34, 11, 69, 18, 9, 13, 
9, 7, 6, 5, 7.8, 7.8, 7.5, 6, 7.3, 7, 7.5, 6, 7, 7, 5.6, 5.6, 
5.4, 11, 10.5, 9.9, 11.7, 8.4, 12.1, 16, 20, 7.6, 17, 6.5, NA, 
8, 22, 24, 44, NA, 13, 13, 12, 18, 23, 23, 73, 4), TDS = c(105L, 
181L, 112L, 144L, 114L, 308L, 96L, 430L, 108L, 108L, 125L, 129L, 
360L, 140L, 95L, 120L, 280L, 130L, 352L, 148L, 107L, 125L, 139L, 
188L, 201L, 178L, 197L, 187L, 182L, 165L, 186L, 191L, 190L, 176L, 
175L, 220L, 163L, 163L, 152L, 221L, 171L, 204L, 174L, 190L, 174L, 
210L, 190L, 180L, 200L, 180L, NA, 120L, 135L, 228L, 14L, NA, 
156L, 140L, 128L, 160L, 215L, 230L, 316L, 163L)), .Names = c(Ca, 
Cl, Cond, Mg, Na, SO4, TDS), class = data.frame, row.names =
c(NA, 
-64L))



B77S wrote:
 
 Please see ?dput
 
 use dput(your data) and paste the output into a reply, thanks.
 
 This way we know what you are working with. 
 
 
 
 
 Rich Shepard wrote:
 
 I would appreciate pointers on what I should read to understand this
 output:
 
   summary(lm(TDS ~ Cond + Ca + Cl + Mg + Na + SO4))
 
 Call:
 lm(formula = TDS ~ Cond + Ca + Cl + Mg + Na + SO4)
 
 Residuals:
 ALL 1 residuals are 0: no residual degrees of freedom!
 
 Coefficients: (6 not defined because of singularities)
  Estimate Std. Error t value Pr(|t|)
 (Intercept)  125 NA  NA   NA
 Cond  NA NA  NA   NA
 CaNA NA  NA   NA
 ClNA NA  NA   NA
 MgNA NA  NA   NA
 NaNA NA  NA   NA
 SO4   NA NA  NA   NA
 
 Residual standard error: NaN on 0 degrees of freedom
(63 observations deleted due to missingness)
 
When I look at the summary for the data frame used for this model I do
 not
 see an excessive number of missing values or indications why there are no
 residual degrees of freedom. The same model applied to 8 other data
 frames
 did not produce similar results.
 
 Puzzled,
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Interpreting-Multiple-Linear-Regression-Summary-tp4020516p4021355.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] Correlation analysis

2011-11-06 Thread B77S
I would start by reading one or more of the introduction manuals available
here:

http://mirrors.ibiblio.org/pub/mirrors/CRAN/








wizi wrote:
 
 Hi everyone, 
 
 I am new to R-project. I did search through the list for my problem but i
 can't find it. I am sorry if this question has been asked.
 
 I would like to perform a correlation analysis between a hiv data and gene
 expression. 
 
 Basically, i have a file that contains: hiv_name, start_position,
 end_position, chromosome. I would like to see if these data has anything
 to do with the location of our genes (I also have another file contains
 gene_name, start_position, end_position, chromosome).
 
 What functions that allow me to do this?
 
 I am very new to R and hopefully someone can guide me to the right
 direction. 
 
 
 Thank you very much,
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Correlation-analysis-tp3996877p3996961.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 with unequal variances

2011-11-01 Thread B77S
the following is a more appropriate forum for your question, seeing as this
has nothing to do with R (per se). 

http://stats.stackexchange.com/questions

good luck.




peak99 wrote:
 
 Hello,
 
 I have some patient data for my masters thesis with three groups (n=16, 19
  20)
 
 I have completed compiling the results of 7 tests, for which one of these
 tests the variances are unequal.
 
 
 I wish to perform an ANOVA between the three groups but for the one test
 with unequal variance (0.001 by both bartlett and levene's test) I am not
 sure what to do.
 
 I thought i would run ANOVA with bonferonni post-test for groups with
 equal variances, then for the test with unequal variance i would use the
 welch correction and games-howell post-test.  Does this sound reasonable?
 
 Someone has also recommended to me to use Kruskal-wallis ANOVA, then use
 Wilcoxon sign rank test pairwise to determine which groups are
 significantly different (ON ALL DATA, both equal and unequal variance
 tests).  I don't think this is right, for two reasons:
 
 1) Kruskal-wallis is for non-gaussian data, and i have no reason to
 believe they are not normal.
 - I have run normality tests which say they are normal, although
 perhaps my sample sizes are too small for a normality test?
 2) i believe running pairwise Wilcoxon sign rank test is not acceptable
 unless there is a post-test correction for multiple comparisons (i am not
 aware of one); also on the wiki page for this test one of the assumptions
 says Under the null hypothesis the distributions of both groups are
 equal which i read to say that the variances must be equal.
 
 So I think there recommendations were based more on sample size and
 normality, and not my issue with variance?
 
 
 Ultimately i would like to know if i am going about this right with my
 deduction (ANOVA/Bonferonni of the test results, but welch correction and
 games-howell for the test with significantly different variances).  and if
 not why and/or what you think is a better option.
 
 most appreciated to any help received!
 


--
View this message in context: 
http://r.789695.n4.nabble.com/help-with-unequal-variances-tp3964779p3965046.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] Subsampling-oversampling from a data frame

2011-11-01 Thread B77S
If no one has a better solution, split it, take a sample of size X from both
and put it back together.


hgwelec wrote:
 
 Dear members,
 
 Consider the following data frame (first 4 rows shown)
 
 
   age sex class
   15   m   low
   20   f  high
   15   f   low
   10   m   low
 
 in my original data set i have 1200 rows and a class distribution of
 low=0.3 and high=0.7
 
 
 My question : how can i create a new data frame as the one shown above but
 with the 'high' class subsampled so that in the new data frame the class
 distribution is low=0.5 and high=0.5?
 
 I tried looking at the sample function and prob option but all examples i
 seen do not use an imbalanced class problem as the one shown above
 
 
 Thank you in advance
 
 
 Thank you in advance
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-oversampling-from-a-data-frame-tp3965771p3965827.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] Subsampling-oversampling from a data frame

2011-11-01 Thread B77S
# Perhaps I misunderstand your original need, but


## I added a few lines to your data and used dput() to get the below data (I
named df)

df- structure(list(age = c(15L, 20L, 15L, 10L, 10L, 12L, 17L, 17L, 
11L, 12L, 16L, 20L, 23L, 14L, 22L, 16L, 10L, 11L, 21L, 10L, 13L, 
17L), sex = structure(c(2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 
2L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L), .Label = c(f, 
m), class = factor), class = structure(c(2L, 1L, 2L, 2L, 
2L, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 
2L, 1L), .Label = c(high, low), class = factor)), .Names = c(age, 
sex, class), class = data.frame, row.names = c(NA, -22L
))

## the following line uses which(), sample(), and rbind(), along with some
indexing to get a new dataframe; see ?which, ?sample, and ?rbind for more
info
# For the indexing, play with it, ... type in df[1:3,1:2] as an example

new_df - rbind(df[sample(which(df$class==low), 4),],
df[sample(which(df$class==high), 4),])

Now replace 4 with the the size of each you want.




hgwelec wrote:
 
 Thank you for your answer.
 
 The problem is that i am learning R now, so i do not know how i could do
 this.
 
 
 I have found the following code but it does not work unfortunately
 (=create distribution 0.1 low class - 0.9 high) :
 
 
 
 data[c(rownames(data.df[data.df$class==high,]),
 sample(rownames(data[data.df$class==low]), 0.1)) , ]
 





2 posts
This post has NOT been accepted by the mailing list yet.
Dear members, 

Consider the following data frame (first 4 rows shown) 


  age sex class 
  15   m   low 
  20   f  high 
  15   f   low 
  10   m   low 

in my original data set i have 1200 rows and a class distribution of low=0.3
and high=0.7 


My question : how can i create a new data frame as the one shown above but
with the 'high' class subsampled so that in the new data frame the class
distribution is low=0.5 and high=0.5? 

I tried looking at the sample function and prob option but all examples i
seen do not use an imbalanced class problem as the one shown above 


Thank you in advance 


Thank you in advance   



--
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-oversampling-from-a-data-frame-tp3965771p3971840.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] Syntax Help for xyplot()

2011-10-24 Thread B77S
Why not format the data like this:
site sampledate SO4 TDS NA Mg Cond Cl Ca
 
i.e. with a column for each parameter?

It seems to me that you summary doesn't make any sense.  Those quantiles are
meaningless as they encompass all the parameters.  Am I missing something?




Rich Shepard wrote:
 
 Thanks to David's help I subset my large data set and produced a smaller
 one for a single stream and 7 factors of interest. The structure of this
 data frame is:
 
 str(burns.tds.anal)
 'data.frame': 718 obs. of  4 variables:
   $ site: Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 4 6 4 4 4 5 5 5
   $ sampdate: Date, format: 1996-06-02 1996-06-02 ...
   $ param   : Factor w/ 7 levels Ca,Cl,Cond,..: 6 7 3 6 3 3 3 3 3 3
   $ quant   : num  194 530 826 36 848 ...
 
 and a summary of it shows:
 
 summary(burns.tds.anal)
sitesampdate   param quant
   BC-3   :460   Min.   :1992-03-27   Ca  : 65   Min.   :   1.00
   BC-2   :107   1st Qu.:1994-09-21   Cl  :148   1st Qu.:  14.03
   BC-1   : 62   Median :1996-05-21   Cond: 94   Median :  64.40
   BC-4   : 38   Mean   :1998-11-19   Mg  : 65   Mean   : 189.47
   BC-1.5 : 28   3rd Qu.:2002-10-31   Na  : 34   3rd Qu.: 285.75
   BC-0.5 : 12   Max.   :2011-05-18   SO4 :155   Max.   :2058.00
   (Other): 11TDS :157   NA's   :   8.00
 
 a sample of the data in burns.tds.anal is:
 
   burns.tds.anal
  site   sampdate param   quant
 82BC-0.5 1996-06-02   SO4  194.00
 83BC-0.5 1996-06-02   TDS  530.00
 6903BC-2 1994-07-25  Cond  826.00
 6905BC-4 1996-08-23   SO4   36.00
 6977BC-2 1994-10-19  Cond  848.00
 6980BC-2 1995-03-16  Cond 1795.00
 6983BC-2 1995-06-21  Cond  640.00
 7833BC-3 1994-01-20  Cond  406.00
 7838BC-3 1994-02-17  Cond  401.00
 7847BC-3 1994-03-24  Cond  441.00
 7854BC-3 1994-06-13  Cond  400.00
 7866BC-3 1994-07-25  Cond  393.00
 7871BC-3 1994-08-18  Cond  420.00
 7877BC-3 1994-10-20  Cond  438.00
 
Perhaps because it's Monday I'm not successfully writing the xyplot()
 command to show the quant, for example, for TDS by site. What I need to do
 is plot the quant values for TDS vs. Cond, TDS vs. SO4, etc.
 
Have I incorrectly subset the data? I know that I've missed something
 but
 cannot determine what it is.
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Syntax-Help-for-xyplot-tp3934533p3934721.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] Syntax Help for xyplot()

2011-10-24 Thread B77S
The following might not be exactly the way to do this, but see the package
reshape and the line of code following your data:


df - structure(list(site = structure(c(1L, 1L, 2L, 4L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c(BC-0.5, BC-2, BC-3, 
BC-4), class = factor), sampdate = structure(c(11L, 11L, 
5L, 12L, 7L, 9L, 10L, 1L, 2L, 3L, 4L, 5L, 6L, 8L), .Label = c(1994-01-20, 
1994-02-17, 1994-03-24, 1994-06-13, 1994-07-25, 1994-08-18, 
1994-10-19, 1994-10-20, 1995-03-16, 1995-06-21, 1996-06-02, 
1996-08-23), class = factor), param = structure(c(2L, 3L, 
1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(Cond, 
SO4, TDS), class = factor), quant = c(194, 530, 826, 36, 
848, 1795, 640, 406, 401, 441, 400, 393, 420, 438)), .Names = c(site, 
sampdate, param, quant), class = data.frame, row.names = c(82, 
83, 6903, 6905, 6977, 6980, 6983, 7833, 7838, 
7847, 7854, 7866, 7871, 7877))

library(reshape)  

 cast(melt(df), site + sampdate ~  param )
Using site, sampdate, param as id variables
 site   sampdate Cond SO4 TDS
1  BC-0.5 1996-06-02   NA 194 530
2BC-2 1994-07-25  826  NA  NA
3BC-2 1994-10-19  848  NA  NA
4BC-2 1995-03-16 1795  NA  NA
5BC-2 1995-06-21  640  NA  NA
6BC-3 1994-01-20  406  NA  NA
7BC-3 1994-02-17  401  NA  NA
8BC-3 1994-03-24  441  NA  NA
9BC-3 1994-06-13  400  NA  NA
10   BC-3 1994-07-25  393  NA  NA
11   BC-3 1994-08-18  420  NA  NA
12   BC-3 1994-10-20  438  NA  NA
13   BC-4 1996-08-23   NA  36  NA



Rich Shepard wrote:
 
 On Mon, 24 Oct 2011, B77S wrote:
 
 Why not format the data like this:
 site sampledate SO4 TDS NA Mg Cond Cl Ca
 
Because I don't know how to reformat the base data frame (chemdata) to
 achieve this.
 
 It seems to me that you summary doesn't make any sense.  Those quantiles
 are meaningless as they encompass all the parameters.  Am I missing
 something?
 
One site/sampdate/param has one value associated with it.
 
 82BC-0.5 1996-06-02   SO4  194.00
 83BC-0.5 1996-06-02   TDS  530.00
 6903BC-2 1994-07-25  Cond  826.00
 6905BC-4 1996-08-23   SO4   36.00
 6977BC-2 1994-10-19  Cond  848.00
 6980BC-2 1995-03-16  Cond 1795.00
 6983BC-2 1995-06-21  Cond  640.00
 7833BC-3 1994-01-20  Cond  406.00
 7838BC-3 1994-02-17  Cond  401.00
 7847BC-3 1994-03-24  Cond  441.00
 7854BC-3 1994-06-13  Cond  400.00
 7866BC-3 1994-07-25  Cond  393.00
 7871BC-3 1994-08-18  Cond  420.00
 7877BC-3 1994-10-20  Cond  438.00
 
I acknowledge that if the chemicals ('param') were in a vector, their
 associated
 concentrations ('quant') in another vector following it, and both
 associated
 with a site and sampdate life would be much better.
 
 Thanks,
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Syntax-Help-for-xyplot-tp3934533p3934857.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] how to delete rows by a list of rownames

2011-10-23 Thread B77S
here is one way

df1 - data.frame(c(1:20), c(21:40), c(31:50))
list1 - c(3, 6, 20)
df2 - df1[-list1,]





hanansela wrote:
 
 Hello
 I have a list of row names that needs to be deleted from a data frame. How
 do i do that? 
 one of the columns in the data frame contains the row names as numbers. I
 can also select by this column (will it be easier?). 
 Thank you
 


--
View this message in context: 
http://r.789695.n4.nabble.com/how-to-delete-rows-by-a-list-of-rownames-tp3930206p3930273.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] Working With Variables Having Different Lengths

2011-10-21 Thread B77S
I know in my experience Cond (conductivity??) doesn't vary much within a
stream except for during high flow events, and I would imagine the same is
true for TDS.  If these are all low flow values, you could possibly
determine a mean/median value to use for the missing data points.  Obviously
this is going to be different if you are sampling storm events.  If you have
stage data and lots of data points, you may be able to model the parameters
as a function of stage. 
HTH




Rich Shepard wrote:
 
 Because of regulatory requirement changes over several decades and weather
 conditions preventing site access the variables in my data set have
 different lengths. I'd like guidance on how to perform linear regressions
 and other models with these variables.
 
For example, there are 2206 rows for the parameter TDS but only 1191
 rows for the parameter Cond. Such discrepancies are common in these
 data.
 
Is there a reference I can read to learn how to analyze such data?
 
 Rich
 
 __
 R-help@ 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://r.789695.n4.nabble.com/Working-With-Variables-Having-Different-Lengths-tp3926023p3926158.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] p value in R - beginners question

2011-10-18 Thread B77S
This is just scientific notation, so 
8.15e-01 is the same as:
 8.15*10^-1
[1] 0.815





niki wrote:
 
 Dear all,
 
 i have done some regression analyses but i do not understand the p value. 
 These are the results
 
t-value  p value
 geno.1   -0.229 0.978 -0.234 8.15e-01
 geno.50.647 1.146  0.565 5.73e-01
 stress:geno.5-1.337 1.022 -1.307 1.92e-01
 
 how can i see if my results are significant ? (apart from looking at the
 t-value). Can someone explain the p values?
 
 thanks
 
 niki
 


--
View this message in context: 
http://r.789695.n4.nabble.com/p-value-in-R-beginners-question-tp3915873p3916308.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] matrix multiplication

2011-10-11 Thread B77S
Your question as answered by Timothy in your previous thread 

http://r.789695.n4.nabble.com/Re-Creating-the-mean-using-algebra-matrix-td3895689.html



flokke wrote:
 
 Dear all, 
 Sorry to bother you with such a stupid question, but I just cannot find
 the solution to my problem.
 
 I'd like to use matrix multiplication for meanA and factorial 3. 
 I use the command meanA%*%factorial 3. 
 But everything I get is: Error in factorial3 %*% A : non-conformable
 arguments
 
 I know that the number of the columns of the first vector has to be the
 same number of rows of the 
 second vector to be able to use matrix multiplication, but that is the
 case here. I also tried it with 
 two columns for factorial 3 and that didnt work either. 
 
 Can someone help me out with this?'
 
 these are my matrices:
 
 meanA
  [,1] [,2]
 [1,] 3.67 4.67
 
 factorial3
  [,1]
 [1,]1
 
 Thank you so much!
 Cheers, maria
 


--
View this message in context: 
http://r.789695.n4.nabble.com/matrix-multiplication-tp3895833p3895860.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] For loop for subset - repeating same over and over?

2011-09-29 Thread B77S
The first suggestion would be to use dput() to allow people on here to access
your data.  
see ?dput

I think you will want to post the output from:

dput(QInflAvgbyPlot)   ## or whatever object contains your data






kelseyann wrote:
 
 Hello, I am using the following script to run an anova for numerous
 species in a table that I have:
 
 
 SiteSpp -
 c(ADHALP,ADLCON,ADLARC,BDALAT,BDPARC,BDLCON,BDLARC,AWCAQU,AWERUS,AWEANG,AWDPSI,BWCSTA,BWHPAU,BWETRI,BWERUS,BWDFIS,BWPARC,BWLCON,BWLARC,BWJBIG)
 
 n.SiteSpp - length(SiteSpp)
 
   for (i in (1:n.SiteSpp)) {
   QInfl.aov - aov(AvgOfnumResponse ~ strTrea*strYear,
 data=QInflAvgbyPlot, subset=(SiteSpp == SiteSpp[i]))
   print(summary(QInfl.aov))
   }
 
 
 The resulting summary just continuously prints the same anova results (For
 ADHALP) over and over again Any suggestions?
 
 Thanks,
 Kelsey
 


--
View this message in context: 
http://r.789695.n4.nabble.com/For-loop-for-subset-repeating-same-over-and-over-tp3858115p3858421.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] Data import

2011-09-27 Thread B77S
I see what you mean.
Sorry and thanks for pointing that out to me Ben.


bbolker wrote:
 
 B77S bps0002 at auburn.edu writes:
 
 
 I have never used that function, but I know that with read.csv() you can
 do
 the following to select only the columns you want:
 
 chosen_vars - read.csv(Workbook1.csv, header=T)[c(variable1,
 variable3)]
 
 
 
   This is not actually selectively importing: it's importing the
 whole thing and *then* selecting the relevant columns.
   If the original poster is trying to avoid importing the whole
 data set because (for example) it's got a gigantic number of
 columns and will be very slow and/or tax their system, then this
 idiom won't help.
 
   Ben Bolker
 
 __
 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://r.789695.n4.nabble.com/Data-import-tp3842196p3848802.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] Data import

2011-09-25 Thread B77S
I have never used that function, but I know that with read.csv() you can do
the following to select only the columns you want:

chosen_vars - read.csv(Workbook1.csv, header=T)[c(variable1,
variable3)]

HTH


sassorauk wrote:
 
 Is it possible to import only certain variables from a SPSS file.
 
 I know that read.spss in the foreign library will bring the data into R
 but can I choose to important only chosen variables from the SPSS dataset
 to R?
 
 Thanks for your help.
 
 R
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Data-import-tp3842196p3842600.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 with Integration Output

2011-09-24 Thread B77S
It  is not simply the answer, it is a list

str(integrate(dnorm, -1.96, 1.96))  
List of 5
 $ value   : num 0.95
 $ abs.error   : num 1.05e-11
 $ subdivisions: int 1
 $ message : chr OK
 $ call: language integrate(f = dnorm, lower = -1.96, upper = 1.96)
 - attr(*, class)= chr integrate


Is this what you want (?):

1 + (integrate(dnorm, -1.96, 1.96)[[1]])  





ChrisQ wrote:
 
 Hi,
 
 I need to do a calculation in R which involves adding the estimate of a
 numerical integration with another number - however, if I add the number
 to
 the output of the intergrate function (which when run on its own provides
 me
 with a number with error), I get the message 'non-numeric argument to
 binary
 operator'. How would I be able to avoid this and use the estimate?
 
 eg: I have the code integrate(dnorm, -1.96, 1.96), which gives the output
 0.9500042 with absolute error  1.0e-11, but if I put in integrate(dnorm,
 -1.96, 1.96)+1, I don't get 1.9500042 - how would I?
 
 Thanks very much, Chris.
 
 --
 View this message in context:
 http://r.789695.n4.nabble.com/Help-with-Integration-Output-tp3839360p3839360.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.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Help-with-Integration-Output-tp3839532p3839552.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] Identifying Package for Function

2011-09-22 Thread B77S
Where is dropvalue(s) mentioned? 

  ?subset 

  subset: logical expression indicating elements or rows to keep:
  missing values are taken as false.

  select: expression, indicating columns to select from a data frame.

drop: passed on to ‘[’ indexing operator.

 ...: further arguments to be passed to or from other methods.

Details:

 This is a generic function, with methods supplied for matrices,
 data frames and vectors (including lists).  Packages and users can
 add further methods.

 For ordinary vectors, the result is simply ‘x[subset 
 !is.na(subset)]’.

 For data frames, the ‘subset’ argument works on the rows.  Note
 that ‘subset’ will be evaluated in the data frame, so columns can
 be referred to (by name) as variables in the expression (see the
 examples).

 The ‘select’ argument exists only for the methods for data frames
 and matrices.  It works by first replacing column names in the
 selection expression with the corresponding column numbers in the
 data frame and then using the resulting integer vector to index
 the columns.  This allows the use of the standard indexing
 conventions so that for example ranges of columns can be specified
 easily, or single columns can be dropped (see the examples).

 The ‘drop’ argument is passed on to the indexing method for
 matrices and data frames: note that the default for matrices is
 different from that for indexing.

Value:

 An object similar to ‘x’ contain just the selected elements (for a
 vector), rows and columns (for a matrix or data frame), and so on.

Author(s):

 Peter Dalgaard and Brian Ripley

See Also:

 ‘[’, ‘transform’

Examples:

 subset(airquality, Temp  80, select = c(Ozone, Temp))
 subset(airquality, Day == 1, select = -Temp)
 subset(airquality, select = Ozone:Wind)
 
 with(airquality, subset(Ozone, Temp  80))
 
 ## sometimes requiring a logical 'subset' argument is a nuisance
 nm - rownames(state.x77)
 start_with_M - nm %in% grep(^M, nm, value=TRUE)
 subset(state.x77, start_with_M, Illiteracy:Murder)





Rich Shepard wrote:
 
 While reading ?subset I'm referred to learn about dropvalues() as a
 following operation. Yet, when I issue ?dropvalue I see, No documentation
 for '?dropvalues' in specified packages and libraries:.
 
How do I identify the library/package that contains a specific function
 such as, in this case, dropvalues()?
 
 Rich
 
 __
 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://r.789695.n4.nabble.com/Identifying-Package-for-Function-tp3835227p3835252.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] adding labels to x,y points

2011-09-21 Thread B77S
#This should work (again, without your data ??)

colon-read.table(c:\\alon.txt,header=T,row.names=1) 

row.names(colon) -paste(g,c(1:nrow(colon)),sep=)   
 
with(colon[1:20,], plot(norm1, norm2, type='n',xlab='x norm1 sample',ylab='y
norm2 sample',main='Norm1 vs Norm2 - 20 genes'))

with(colon, text(norm1, norm2, label = row.names(colon[1:20,])) 




baumeist wrote:
 
 Hi,
 I am new to R.
 
 I have a matrix that I have assigned to the object “colon”.
 
 colon-read.table(c:\\alon.txt,header=T,row.names=1)
 
 attach(colon)
 names(colon)
 
 The dimenstions are 2000   62.
 
 Each of the 62 columns (titled norm1, norm2, norm3, etc) has 2000
 different numbers (‘continuous’ values) within it.
 
 I have also assigned a name for each of the 2000 rows of the dataframe
 with a prefix (i.e. g1 …. g2000) using the code (not sure if I did this
 right):
 
 colon-paste(g,c(1:nrow(colon)),sep=)
 
 I have plotted the first 20 values from two of the columns(samples).
 
 x-c(norm1[1:20])
 
 y-c(norm2[1:20])
 
 plot(x,y,type='n',xlab='x norm1 sample',ylab='y norm2 sample',main='Norm1
 vs Norm2 - 20
 genes')
 
 points(x,y,pch=15,col='blue')
 
 Now I wish to assign labels to each point (above each point (i.e. pos=3)
 in the plot with “g1 to g20 corresponding to each row but I am having
 trouble with this step.
 
 I have tried:
 
 text(x,y, label = row.names(colon[1:20])) 
 
 but nothing happens. 
 
 Any suggestions?
 
 Thanks in advance
 MAB
 


--
View this message in context: 
http://r.789695.n4.nabble.com/adding-labels-to-x-y-points-tp3828461p3830363.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] adding labels to x,y points

2011-09-20 Thread B77S
I don't have access to your alon.txt file (see ?dput for future posts),
but...

I'm pretty sure info you want isn't in row.names(colon[1:2])
it should just be 

text(x,y, label = colon[1:20]) 


??
HTH



baumeist wrote:
 
 Hi,
 I am new to R.
 
 I have a matrix that I have assigned to the object “colon”.
 
 colon-read.table(c:\\alon.txt,header=T,row.names=1)
 
 attach(colon)
 names(colon)
 
 The dimenstions are 2000   62.
 
 Each of the 62 columns (titled norm1, norm2, norm3, etc) has 2000
 different numbers (‘continuous’ values) within it.
 
 I have also assigned a name for each of the 2000 rows of the dataframe
 with a prefix (i.e. g1 …. g2000) using the code (not sure if I did this
 right):
 
 colon-paste(g,c(1:nrow(colon)),sep=)
 
 I have plotted the first 20 values from two of the columns(samples).
 
 x-c(norm1[1:20])
 
 y-c(norm2[1:20])
 
 plot(x,y,type='n',xlab='x norm1 sample',ylab='y norm2 sample',main='Norm1
 vs Norm2 - 20
 genes')
 
 points(x,y,pch=15,col='blue')
 
 Now I wish to assign labels to each point (above each point (i.e. pos=3)
 in the plot with “g1 to g20 corresponding to each row but I am having
 trouble with this step.
 
 I have tried:
 
 text(x,y, label = row.names(colon[1:20])) 
 
 but nothing happens. 
 
 Any suggestions?
 
 Thanks in advance
 MAB
 


--
View this message in context: 
http://r.789695.n4.nabble.com/adding-labels-to-x-y-points-tp3828461p3828545.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] adding labels to x,y points

2011-09-20 Thread B77S
Actually, you appear to have re-assigned your object “colon” (from
c:\\alon.txt) with a character vector of intended row.names.

so use 

row.names(colon) -paste(g,c(1:nrow(colon)),sep=)




B77S wrote:
 
 I don't have access to your alon.txt file (see ?dput for future posts),
 but...
 
 I'm pretty sure the info you want is not in row.names(colon[1:2])
 
 should just be using:
 
 text(x,y, label = colon[1:20,])  
 
 ??
 
 HTH
 
 
 
 baumeist wrote:
 
 Hi,
 I am new to R.
 
 I have a matrix that I have assigned to the object “colon”.
 
 colon-read.table(c:\\alon.txt,header=T,row.names=1)
 
 attach(colon)
 names(colon)
 
 The dimenstions are 2000   62.
 
 Each of the 62 columns (titled norm1, norm2, norm3, etc) has 2000
 different numbers (‘continuous’ values) within it.
 
 I have also assigned a name for each of the 2000 rows of the dataframe
 with a prefix (i.e. g1 …. g2000) using the code (not sure if I did this
 right):
 
 colon-paste(g,c(1:nrow(colon)),sep=)
 
 I have plotted the first 20 values from two of the columns(samples).
 
 x-c(norm1[1:20])
 
 y-c(norm2[1:20])
 
 plot(x,y,type='n',xlab='x norm1 sample',ylab='y norm2
 sample',main='Norm1 vs Norm2 - 20
 genes')
 
 points(x,y,pch=15,col='blue')
 
 Now I wish to assign labels to each point (above each point (i.e. pos=3)
 in the plot with “g1 to g20 corresponding to each row but I am having
 trouble with this step.
 
 I have tried:
 
 text(x,y, label = row.names(colon[1:20])) 
 
 but nothing happens. 
 
 Any suggestions?
 
 Thanks in advance
 MAB
 
 


--
View this message in context: 
http://r.789695.n4.nabble.com/adding-labels-to-x-y-points-tp3828461p3828665.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] graph bugs using R on MAC

2011-09-18 Thread B77S
Have you been shown how to save a graph as a JPEG or PNG?

try this:

png(myGraph.png)
plot(your_data)
dev.off()

A png will appear in your working directory, which can be imported into the
Word document.
You can do the same with a JPEG

see ?jpeg or ?png and ?dev.off

HTH
 


bonnieyuan wrote:
 
 This is has been bugging me for a long time. Nobody around me seems to  
 have this problem. I hope someone on the forum could help me.
 
 When I generate a R graph and want to bring the image into Word. I  
 cannot copy and paste it like many of my classmates can do. The  
 Select in Edit menu have all options grayed out. So what I ended up  
 doing is to save it as pdf file and bring it into Word. But if I use  
 Identify in the Plot statement, there will be values labels on the  
 graph when you click on the observation. For some reason, these labels  
 don't show up in the pdf file.
 
 So the last resort I have is prinscreen, which always have irrelevant  
 things showing.
 
 I've tried updating R/OS and all softwares on my MAC, but nothing  
 seems to do anything. I have OX 10.6.8. Does this problem sound  
 familiar to anyone?
 
 Thanks in advance!
 
 Bonnie Yuan
 
 __
 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://r.789695.n4.nabble.com/graph-bugs-using-R-on-MAC-tp3822460p3822480.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] AIC

2011-09-18 Thread B77S
This isn't a question about R; more appropriate for stackexchange.

Here is one string that might interest you:

http://stats.stackexchange.com/questions/4997/can-aic-compare-across-different-types-of-model






Tania Sav wrote:
 
 Hello,
 
 I'm using AIC() to choose a better model. I have 3 options: 
 1) y=ax+b 
 2) y=ax^2 +bx + c
 3) y=a(1-exp(-x/b)) + c
 
 Is it ok to use AIC() for determine wich is the better equation to use for
 fit to my data?
 
 Thanks
 Tania
 

Tania Sav wrote:
 
 Hello,
 
 I'm using AIC() to choose a better model. I have 3 options: 
 1) y=ax+b 
 2) y=ax^2 +bx + c
 3) y=a(1-exp(-x/b)) + c
 
 Is it ok to use AIC() for determine wich is the better equation to use for
 fit to my data?
 
 Thanks
 Tania
 


--
View this message in context: 
http://r.789695.n4.nabble.com/AIC-tp3820732p3822647.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] onet.permutation()

2011-09-17 Thread B77S
** I am not a statistician, but...
 
The default arguments are:
onet.permutation(x, nsim=2000, plotit=TRUE)

you are making nsim=4   (this parameter is not the size of each sample, it
is the number of samples taken)
You are building the distribution for a statistical test through random
sampling, so you want to have MANY MANY random samples, not just 4.





song_gpqg wrote:
 
 I saw the manual of this function but not sure what to do. 
 I have a array contain 7 numbers and want to choose 4 to do permutation
 test. But using this function with parameters as
 onet.permutation(scores,4), it returns 0. Instead, with no parameter,
 onet.permutation(), it returns something but every time it's different.
 Please tell me how am I supposed to do it.
 Thanks a lot
 


--
View this message in context: 
http://r.789695.n4.nabble.com/onet-permutation-tp3820372p3820671.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] Mystified - comparing chron times

2011-09-16 Thread B77S
I'm sure Sarah's solution works (and she knows more about R than myself), but
I ran into a similar problem and used:
as.character(start.time)==as.character(expected_start.time)

good luck regardless.

-BS


Sarah Goslee wrote:
 
 Sounds like a case for FAQ 7.31, or, yet another machine precision issue.
 Try all.equal() instead of ==
 
 Sarah
 
 On Fri, Sep 16, 2011 at 7:36 AM, mebstyne lt;mebst...@me.comgt; wrote:
 I have two local variables: startTime and expectedStartTime.  Both are
 chron
 related objects.
 When I look at the class for the objects I can see they are of class
 times.
 When I print them to the console, they both read: 09:30:00
 When I print them as.numeric(), they both read: 0.3958333
 When I try and compare them: (as.numeric(startTime) ==
 as.numeric(expectedStartTime)) it returns FALSE.

 I'm mystified.  I would expect them to be true.
 Perhaps a key to the riddle is how the two objects were created.

 startTime was created by reading a text field from a socket, converting
 it
 into a chron object using chron(x, %m/$d/%Y %H:%M:%S), then finally I
 created a time out of the chron by doing a quick butchering of the
 integer
 portion of the numeric: (times(as.numeric(x) - as.integer(x))

 expectedStartTime was created by the command times('09:30:00')

 Any suggestions?  Tips?  Alternative approaches?  I've pulled too many
 hairs
 triaging this.
 All hands welcomed on this little challenge.

 Big picture goal of what I'm doing: I have a list of chron objects with
 both
 dates and times portion filled out and I'm trying to determine if the
 time
 is a specific time (specific to the minute).

 Thanks!

 -Michael

 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org
 
 __
 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://r.789695.n4.nabble.com/Mystified-comparing-chron-times-tp3817855p3818176.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] installation of BiodiversityR package

2011-09-15 Thread B77S
My guess is that anyone willing to help will want more information.  
What version of R do you have(?), for example.

BiodiversityR Depends on R version ≥ 2.13.1, and vegan ≥ 1.17-12




SG wrote:
 
 I have installed R on windows 7 machine.
 In the install packages I can't find BiodiversityR package.
 I was wondering if I can get some help with the installation process.
 Thanks.
 


--
View this message in context: 
http://r.789695.n4.nabble.com/installation-of-BiodiversityR-package-tp3816807p3816823.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] R functions

2011-09-15 Thread B77S
You'll never figure it out if you don't play around with your data.  

Assuming you have been able to import the data, a good place to start is to
look at what tools you have available.Check out this:
http://cran.r-project.org/doc/contrib/Short-refcard.pdf

check out things like
?which
?max
?unique


You have 2 choices, hope that someone hands you a solution, or fiddle around
until you become proficient.

Good luck.



sujitha wrote:
 
 Hi group,
 I am trying to right a code to do the following
 This is how the test file looks like:
 Chr start end sample1 sample2
 chr2 9896633 9896683 0 0
 chr2 9896639 9896690 0 0
 chr2 14314039 14314098 0 -0.35
 chr2 14404467 14404502 0 -0.35
 chr2 14421718 14421777 -0.43 -0.35
 chr2 16031710 16031769 -0.43 -0.35
 chr2 16036178 16036237 -0.43 -0.35
 chr2 16048665 16048724 -0.43 -0.35
 chr2 37491676 37491735 0 0
 chr2 37702947 37703009 0 0
 
 Now I want to summarize the values like 
 Sample Chr Start End Values Probes
 1 chr2 9896633 14404502 0 4
 1 chr2 14421718 16048724 -0.43 4
 1 chr2 37491676 37703001 0 2
 2 chr2 9896633 9896690 0 2
 2 chr2 14314039 16048724 -0.35 6
 2 chr2 37491676 37703009 0 2
 
 Here the start for the first line would be the least value until values
 are similiar (4) then the end would be highest value. The values is the
 unique value among the common values.
 Can I get some ideas or suggestions to perform this because I am new to
 hard core program in R? 
 waiting for your suggestions,
 Thanks,
 suji
 


--
View this message in context: 
http://r.789695.n4.nabble.com/R-functions-tp3816748p3816844.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] R functions

2011-09-15 Thread B77S
If your data is named 'test_file'

then use dput(test_file) 

You can copy and paste the results here so people can more easily try and
help you.

see
?dput




sujitha wrote:
 
 Hi group,
 I am trying to right a code to do the following
 This is how the test file looks like:
 Chr start end sample1 sample2
 chr2 9896633 9896683 0 0
 chr2 9896639 9896690 0 0
 chr2 14314039 14314098 0 -0.35
 chr2 14404467 14404502 0 -0.35
 chr2 14421718 14421777 -0.43 -0.35
 chr2 16031710 16031769 -0.43 -0.35
 chr2 16036178 16036237 -0.43 -0.35
 chr2 16048665 16048724 -0.43 -0.35
 chr2 37491676 37491735 0 0
 chr2 37702947 37703009 0 0
 
 Now I want to summarize the values like 
 Sample Chr Start End Values Probes
 1 chr2 9896633 14404502 0 4
 1 chr2 14421718 16048724 -0.43 4
 1 chr2 37491676 37703001 0 2
 2 chr2 9896633 9896690 0 2
 2 chr2 14314039 16048724 -0.35 6
 2 chr2 37491676 37703009 0 2
 
 Here the start for the first line would be the least value until values
 are similiar (4) then the end would be highest value. The values is the
 unique value among the common values.
 Can I get some ideas or suggestions to perform this because I am new to
 hard core program in R? 
 waiting for your suggestions,
 Thanks,
 suji
 


--
View this message in context: 
http://r.789695.n4.nabble.com/R-functions-tp3816748p3817055.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] R functions

2011-09-15 Thread B77S
Suji,

# Here is your data (test).

test - structure(list(Chr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L), .Label = chr2, class = factor), start = c(9896633L, 
9896639L, 14314039L, 14404467L, 14421718L, 16031710L, 16036178L, 
16048665L, 37491676L, 37702947L), end = c(9896683L, 9896690L, 
14314098L, 14404502L, 14421777L, 16031769L, 16036237L, 16048724L, 
37491735L, 37703009L), sample1 = c(0, 0, 0, 0, -0.43, -0.43, 
-0.43, -0.43, 0, 0), sample2 = c(0, 0, -0.35, -0.35, -0.35, -0.35, 
-0.35, -0.35, 0, 0)), .Names = c(Chr, start, end, sample1, 
sample2), class = data.frame, row.names = c(NA, -10L))

# Here is where you will likely want to start (but there are many ways to
skin a cat).

test2 - data.frame(c(rle(test[,4])[[2]], rle(test[,5])[[2]]),
c(rle(test[,4])[[1]], rle(test[,5])[[1]]))
names(test2) - c(Values, Probes)


 test2
  Values Probes
1   0.00  4
2  -0.43  4
3   0.00  2
4   0.00  2
5  -0.35  6
6   0.00  2


# Obviously this is not exactly what you wanted, only the last 2 columns. 
Obviously, the tricky part remains... but I hope this helps.  


##



B77S wrote:
 
 If your data is named 'test_file'
 
 then use dput(test_file) 
 
 You can copy and paste the results here so people can more easily try and
 help you.
 
 see
 ?dput
 
 
 
 
 sujitha wrote:
 
 Hi group,
 I am trying to right a code to do the following
 This is how the test file looks like:
 Chr start end sample1 sample2
 chr2 9896633 9896683 0 0
 chr2 9896639 9896690 0 0
 chr2 14314039 14314098 0 -0.35
 chr2 14404467 14404502 0 -0.35
 chr2 14421718 14421777 -0.43 -0.35
 chr2 16031710 16031769 -0.43 -0.35
 chr2 16036178 16036237 -0.43 -0.35
 chr2 16048665 16048724 -0.43 -0.35
 chr2 37491676 37491735 0 0
 chr2 37702947 37703009 0 0
 
 Now I want to summarize the values like 
 Sample Chr Start End Values Probes
 1 chr2 9896633 14404502 0 4
 1 chr2 14421718 16048724 -0.43 4
 1 chr2 37491676 37703001 0 2
 2 chr2 9896633 9896690 0 2
 2 chr2 14314039 16048724 -0.35 6
 2 chr2 37491676 37703009 0 2
 
 Here the start for the first line would be the least value until values
 are similiar (4) then the end would be highest value. The values is the
 unique value among the common values.
 Can I get some ideas or suggestions to perform this because I am new to
 hard core program in R? 
 waiting for your suggestions,
 Thanks,
 suji
 
 


--
View this message in context: 
http://r.789695.n4.nabble.com/R-functions-tp3816748p3817431.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] reshaping data

2011-09-07 Thread B77S
I have the following data (see RawData using dput below) 

How do I get it in the following 3 column format (CO2 measurements are the
elements of the original data frame).  I'm sure the package reshape is where
I should look, but I haven't figured out how.

Thanks ahead of time 

 Month Year CO2 
J   1958
F   1958
M   1958315.71
A   1958317.45
M.1 1958317.5
J.1 1958
J.2 1958315.86
A.1 1958314.93
S   1958313.19
O   1958
N   1958313.34
D   1958314.67
J   1959315.58
F   1959316.47


# here is the data

RawData - structure(list(Year = c(1958, 1959, 1960, 1961, 1962, 1963, 1964, 
1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975, 
1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, 
1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 
1998, 1999, 2000, 2001, 2002, 2003, 2004), J = c(NA, 315.58, 
316.43, 316.89, 317.94, 318.74, 319.57, 319.44, 320.62, 322.33, 
322.57, 324, 325.06, 326.17, 326.77, 328.54, 329.35, 330.4, 331.74, 
332.92, 334.97, 336.23, 338.01, 339.23, 340.75, 341.37, 343.7, 
344.97, 346.29, 348.02, 350.43, 352.76, 353.66, 354.72, 355.98, 
356.7, 358.36, 359.96, 362.05, 363.18, 365.32, 368.15, 369.14, 
370.28, 372.43, 374.68, 376.79), F = c(NA, 316.47, 316.97, 317.7, 
318.56, 319.08, NA, 320.44, 321.59, 322.5, 323.15, 324.42, 325.98, 
326.68, 327.63, 329.56, 330.71, 331.41, 332.56, 333.42, 335.39, 
336.76, 338.36, 340.47, 341.61, 342.52, 344.51, 346, 346.96, 
348.47, 351.72, 353.07, 354.7, 355.75, 356.72, 357.16, 358.91, 
361, 363.25, 364, 366.15, 368.87, 369.46, 371.5, 373.09, 375.63, 
377.37), M = c(315.71, 316.65, 317.58, 318.54, 319.69, 319.86, 
NA, 320.89, 322.39, 323.04, 323.89, 325.64, 326.93, 327.18, 327.75, 
330.3, 331.48, 332.04, 333.5, 334.7, 336.64, 337.96, 340.08, 
341.38, 342.7, 343.1, 345.28, 347.43, 347.86, 349.42, 352.22, 
353.68, 355.39, 357.16, 357.81, 358.38, 359.97, 361.64, 364.03, 
364.57, 367.31, 369.59, 370.52, 372.12, 373.52, 376.11, 378.41
), A = c(317.45, 317.71, 319.03, 319.48, 320.58, 321.39, NA, 
322.13, 323.7, 324.42, 325.02, 326.66, 328.13, 327.78, 329.72, 
331.5, 332.65, 333.31, 334.58, 336.07, 337.76, 338.89, 340.77, 
342.51, 343.56, 344.94, 347.08, 348.35, 349.55, 350.99, 353.59, 
355.42, 356.2, 358.6, 359.15, 359.46, 361.26, 363.45, 364.72, 
366.35, 368.61, 371.14, 371.66, 372.87, 374.86, 377.65, 380.52
), M.1 = c(317.5, 318.29, 320.03, 320.58, 321.01, 322.24, 322.23, 
322.16, 324.07, 325, 325.57, 327.38, 328.07, 328.92, 330.07, 
332.48, 333.09, 333.96, 334.87, 336.74, 338.01, 339.47, 341.46, 
342.91, 344.13, 345.75, 347.43, 348.93, 350.21, 351.84, 354.22, 
355.67, 357.16, 359.34, 359.66, 360.28, 361.68, 363.79, 365.41, 
366.79, 369.29, 371, 371.82, 374.02, 375.55, 378.35, 380.63), 
J.1 = c(NA, 318.16, 319.59, 319.78, 320.61, 321.47, 321.89, 
321.87, 323.75, 324.09, 325.36, 326.7, 327.66, 328.57, 329.09, 
332.07, 332.25, 333.59, 334.34, 336.27, 337.89, 339.29, 341.17, 
342.25, 343.35, 345.32, 346.79, 348.25, 349.54, 351.25, 353.79, 
355.13, 356.22, 358.24, 359.25, 359.6, 360.95, 363.26, 364.97, 
365.62, 368.87, 370.35, 371.7, 373.3, 375.4, 378.13, 379.57
), J.2 = c(315.86, 316.55, 318.18, 318.58, 319.61, 319.74, 
320.44, 321.21, 322.4, 322.55, 324.14, 325.89, 326.35, 327.37, 
328.05, 330.87, 331.18, 331.91, 333.05, 334.93, 336.54, 337.73, 
339.56, 340.49, 342.06, 343.99, 345.4, 346.56, 347.94, 349.52, 
352.39, 353.9, 354.82, 356.17, 357.03, 357.57, 359.55, 361.9, 
363.65, 364.47, 367.64, 369.27, 370.12, 371.62, 374.02, 376.62, 
377.79), A.1 = c(314.93, 314.8, 315.91, 316.79, 317.4, 317.77, 
318.7, 318.87, 320.37, 320.92, 322.11, 323.67, 324.69, 325.43, 
326.32, 329.31, 329.4, 330.06, 330.94, 332.75, 334.68, 336.09, 
337.6, 338.43, 339.82, 342.39, 343.28, 344.69, 345.91, 348.1, 
350.44, 351.67, 352.91, 354.03, 355, 355.52, 357.49, 359.46, 
361.49, 362.51, 365.77, 366.94, 368.12, 369.55, 371.49, 374.5, 
375.86), S = c(313.19, 313.84, 314.16, 314.99, 316.26, 316.21, 
316.7, 317.81, 318.64, 319.26, 320.33, 322.38, 323.1, 323.36, 
324.84, 327.51, 327.44, 328.56, 329.3, 331.58, 332.76, 333.91, 
335.88, 336.69, 337.97, 339.86, 341.07, 343.09, 344.86, 346.44, 
348.72, 349.8, 350.96, 352.16, 353.01, 353.7, 355.84, 358.06, 
359.46, 360.19, 363.9, 364.63, 366.62, 367.96, 370.71, 372.99, 
374.06), O = c(NA, 313.34, 313.83, 315.31, 315.42, 315.99, 
316.87, 317.3, 318.1, 319.39, 320.25, 321.78, 323.07, 323.56, 
325.2, 327.18, 327.37, 328.34, 328.94, 331.16, 332.54, 333.86, 
336.01, 336.85, 337.86, 339.99, 341.35, 342.8, 344.17, 346.36, 
348.88, 349.99, 351.18, 352.21, 353.31, 353.98, 355.99, 357.75, 
359.6, 360.77, 364.23, 365.12, 366.73, 368.09, 370.24, 373, 
374.24), N = c(313.34, 314.81, 315, 316.1, 316.69, 317.07, 
317.68, 318.87, 319.79, 320.72, 321.32, 322.85, 324.01, 324.8, 
326.5, 

Re: [R] reshaping data

2011-09-07 Thread B77S
The terminology (melt, cast, recast) just isn't intuitive to me; but I
understand how to use melt now.
Thanks!  



Justin Haynes wrote:
 
 look at the melt function in reshape, specifically ?melt.data.frame
 
 require(reshape)
 Raw.melt-melt(RawData,id.vars='Year',variable_name='Month')
 
 there is an additional feature in the melt function for handling na
 values.
 names(Raw.melt)[3]-'CO2'
 
 head(Raw.melt)
   Year MonthCO2
 1 1958 J NA
 2 1959 J 315.58
 3 1960 J 316.43
 4 1961 J 316.89
 5 1962 J 317.94
 6 1963 J 318.74

 
 you can order your data.frame if you'd like
 
 Raw.melt-Raw.melt[order(Raw.melt$Year,Raw.melt$Month),]
 
 head(Raw.melt)
 Year MonthCO2
 1   1958 J NA
 48  1958 F NA
 95  1958 M 315.71
 142 1958 A 317.45
 189 1958   M.1 317.50
 236 1958   J.1 NA
 
 
 On Wed, Sep 7, 2011 at 7:35 AM, B77S lt;bps0...@auburn.edugt; wrote:
 
 I have the following data (see RawData using dput below)

 How do I get it in the following 3 column format (CO2 measurements are
 the
 elements of the original data frame).  I'm sure the package reshape is
 where
 I should look, but I haven't figured out how.

 Thanks ahead of time

  Month Year CO2
 J   1958
 F   1958
 M   1958315.71
 A   1958317.45
 M.1 1958317.5
 J.1 1958
 J.2 1958315.86
 A.1 1958314.93
 S   1958313.19
 O   1958
 N   1958313.34
 D   1958314.67
 J   1959315.58
 F   1959316.47


 # here is the data

 RawData - structure(list(Year = c(1958, 1959, 1960, 1961, 1962, 1963,
 1964,
 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, 1974, 1975,
 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986,
 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
 1998, 1999, 2000, 2001, 2002, 2003, 2004), J = c(NA, 315.58,
 316.43, 316.89, 317.94, 318.74, 319.57, 319.44, 320.62, 322.33,
 322.57, 324, 325.06, 326.17, 326.77, 328.54, 329.35, 330.4, 331.74,
 332.92, 334.97, 336.23, 338.01, 339.23, 340.75, 341.37, 343.7,
 344.97, 346.29, 348.02, 350.43, 352.76, 353.66, 354.72, 355.98,
 356.7, 358.36, 359.96, 362.05, 363.18, 365.32, 368.15, 369.14,
 370.28, 372.43, 374.68, 376.79), F = c(NA, 316.47, 316.97, 317.7,
 318.56, 319.08, NA, 320.44, 321.59, 322.5, 323.15, 324.42, 325.98,
 326.68, 327.63, 329.56, 330.71, 331.41, 332.56, 333.42, 335.39,
 336.76, 338.36, 340.47, 341.61, 342.52, 344.51, 346, 346.96,
 348.47, 351.72, 353.07, 354.7, 355.75, 356.72, 357.16, 358.91,
 361, 363.25, 364, 366.15, 368.87, 369.46, 371.5, 373.09, 375.63,
 377.37), M = c(315.71, 316.65, 317.58, 318.54, 319.69, 319.86,
 NA, 320.89, 322.39, 323.04, 323.89, 325.64, 326.93, 327.18, 327.75,
 330.3, 331.48, 332.04, 333.5, 334.7, 336.64, 337.96, 340.08,
 341.38, 342.7, 343.1, 345.28, 347.43, 347.86, 349.42, 352.22,
 353.68, 355.39, 357.16, 357.81, 358.38, 359.97, 361.64, 364.03,
 364.57, 367.31, 369.59, 370.52, 372.12, 373.52, 376.11, 378.41
 ), A = c(317.45, 317.71, 319.03, 319.48, 320.58, 321.39, NA,
 322.13, 323.7, 324.42, 325.02, 326.66, 328.13, 327.78, 329.72,
 331.5, 332.65, 333.31, 334.58, 336.07, 337.76, 338.89, 340.77,
 342.51, 343.56, 344.94, 347.08, 348.35, 349.55, 350.99, 353.59,
 355.42, 356.2, 358.6, 359.15, 359.46, 361.26, 363.45, 364.72,
 366.35, 368.61, 371.14, 371.66, 372.87, 374.86, 377.65, 380.52
 ), M.1 = c(317.5, 318.29, 320.03, 320.58, 321.01, 322.24, 322.23,
 322.16, 324.07, 325, 325.57, 327.38, 328.07, 328.92, 330.07,
 332.48, 333.09, 333.96, 334.87, 336.74, 338.01, 339.47, 341.46,
 342.91, 344.13, 345.75, 347.43, 348.93, 350.21, 351.84, 354.22,
 355.67, 357.16, 359.34, 359.66, 360.28, 361.68, 363.79, 365.41,
 366.79, 369.29, 371, 371.82, 374.02, 375.55, 378.35, 380.63),
J.1 = c(NA, 318.16, 319.59, 319.78, 320.61, 321.47, 321.89,
321.87, 323.75, 324.09, 325.36, 326.7, 327.66, 328.57, 329.09,
332.07, 332.25, 333.59, 334.34, 336.27, 337.89, 339.29, 341.17,
342.25, 343.35, 345.32, 346.79, 348.25, 349.54, 351.25, 353.79,
355.13, 356.22, 358.24, 359.25, 359.6, 360.95, 363.26, 364.97,
365.62, 368.87, 370.35, 371.7, 373.3, 375.4, 378.13, 379.57
), J.2 = c(315.86, 316.55, 318.18, 318.58, 319.61, 319.74,
320.44, 321.21, 322.4, 322.55, 324.14, 325.89, 326.35, 327.37,
328.05, 330.87, 331.18, 331.91, 333.05, 334.93, 336.54, 337.73,
339.56, 340.49, 342.06, 343.99, 345.4, 346.56, 347.94, 349.52,
352.39, 353.9, 354.82, 356.17, 357.03, 357.57, 359.55, 361.9,
363.65, 364.47, 367.64, 369.27, 370.12, 371.62, 374.02, 376.62,
377.79), A.1 = c(314.93, 314.8, 315.91, 316.79, 317.4, 317.77,
318.7, 318.87, 320.37, 320.92, 322.11, 323.67, 324.69, 325.43,
326.32, 329.31, 329.4, 330.06, 330.94, 332.75, 334.68, 336.09,
337.6, 338.43, 339.82, 342.39, 343.28, 344.69, 345.91, 348.1,
350.44, 351.67, 352.91, 354.03, 355, 355.52, 357.49, 359.46,
361.49, 362.51, 365.77, 366.94, 368.12, 369.55, 371.49, 374.5,
375.86), S = c(313.19, 313.84, 314.16

Re: [R] Alternatives to integrate?

2011-09-01 Thread B77S
package caTools
see ?trapz


. wrote:
 
 Hi all,
 
 is there any alternative to the function integrate?
 
 Any comments are welcome.
 
 Thanks in advance.
 
 __
 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://r.789695.n4.nabble.com/Alternatives-to-integrate-tp3783624p3783645.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] R Help finding Mean

2011-09-01 Thread B77S
see ?mean
Then avoid other peoples code. 


cenae27 wrote:
 
 bob-read.csv('shi.csv', header=T)
 
 newmean-matrix(0, test, dim(bob)[2]-6);a-0; for (i in
 c(4,8:(dim(bob)[2])))
 {a-a+1;newmean[,a]-tapply(bob[,i], bob$Exam, mean)}
 colnames(newmean)-colnames(bob)[c(4,8:(dim(bob)[2]))]
 
 Could anyone please help me what does the above code does ... I want to
 find mean ... but would like to know what exactly is the above code doing.
 
 Thanks for your help.
 Cenae
 

--
View this message in context: 
http://r.789695.n4.nabble.com/R-Help-finding-Mean-tp3783400p3783652.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] Howto convert Linear Regression data to text

2011-08-24 Thread B77S
If I understand you correctly, see ?paste

and the following to extract the values you require:

summary(res)[[4]][1] 

summary(res)[[4]][2]  

summary(res)[[8]]

HTH



ashz wrote:
 
 Dear all,
 
 How can I covert lm data to text in the form of y=ax+b, r2 and how do I
 calculate R-squared(r2)?
 
 Thanks. 
  
 Code:
 x=18:29
 y=c(7.1,7,7.7,8.2,8.8,9.7,9.9,7.1,7.2,8.8,8.7,8.5)
 res=lm(y~x)
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Howto-convert-Linear-Regression-data-to-text-tp3766230p3767009.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] Importing data from MS EXCEL (.xls) to R XXXX

2011-08-24 Thread B77S
I agree with Ken.. if you can, save it as a CSV file.  But if you have a
bunch of these, then it isn't very efficient.  I use read.xlsx() from the
package xlsx.  

I notice that you are using the full path.. have you tried changing
directories?... I find it is best to compartmentalize my work and (with a
few exceptions) work within a folder.

good luck.

 


Dan Abner wrote:
 
 Hello everyone,
 
 What is the simplest, most RELIABLE way to import data from MS EXCEL
 (.xls)
 format to R? In the past I have used the read.xls() function from the
 xlsReadWrite package, however, I have been wrestling with it all afternoon
 long with no success. I continue to receive the following error message:
 
 
 {widge-read.xls(F:\\Classes\\Z1.Data\\stat.3010\\WidgeOne.xls,
 + colNames=TRUE,sheet=1)}
 Error in .Call(ReadXls, file, colNames, sheet, type, from, rowNames,  :
   Incorrect number of arguments (11), expecting 10 for 'ReadXls'
 
 Any insight/suggestions/assistance is appreciated.
 
 Thank you,
 
 Dan
 
   [[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://r.789695.n4.nabble.com/Importing-data-from-MS-EXCEL-xls-to-R--tp3766864p3767063.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] Ordinary Least Products regression in R

2011-07-27 Thread B77S
If this is the same as geometric mean regression (aka: line of organic
correlation-- Kruskal 1953), I ended up writing my own function  (although
one may exist and I didn't see it).





Bill Hyman wrote:
 
 Dear all,
 
 Does any one know if any R package or function can do Ordinary Least
 Products regression? Many thanks!
 
 Bill
 
 __
 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://r.789695.n4.nabble.com/Ordinary-Least-Products-regression-in-R-tp3697635p3698343.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] Odd behaviour of as.POSIXct

2011-07-15 Thread B77S
day doesn't exist?
That would be the 1st problem.



Johannes Egner wrote:
 
 Dear all,
 
 how come the first loop in the below fails, but the second performs as
 expected?
 
 days - as.Date( c(2000-01-01, 2000-01-02) )
 
 for(day in days)
 {
 as.POSIXct(day)
 }
 
 for( n in 1:length(days) )
 {
 show(as.POSIXct(days[n]))
 }
 
 Many thanks, Jo
 
   [[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://r.789695.n4.nabble.com/Odd-behaviour-of-as-POSIXct-tp3670414p3670454.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] installation of package 'mapproj' had non-zero exit status

2011-07-12 Thread B77S
## Hello.. I have asked a similar question, but this is not fixed as before. 

## I am running the following using Ubuntu OS:

R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)


## when I do this: 

 install.packages(mapproj, dependencies=T)


## I get this:  

Installing package(s) into ‘/home/brad/R/x86_64-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
also installing the dependency ‘maps’

trying URL 'http://cran.case.edu/src/contrib/maps_2.1-6.tar.gz'
Content type 'application/x-gzip' length 1371854 bytes (1.3 Mb)
opened URL
==
downloaded 1.3 Mb

trying URL 'http://cran.case.edu/src/contrib/mapproj_1.1-8.3.tar.gz'
Content type 'application/x-gzip' length 23955 bytes (23 Kb)
opened URL
==
downloaded 23 Kb

* installing *source* package ‘maps’ ...
** libs
** arch - 
gcc -std=gnu99 -O3 -pipe  -gGmake.c   -o Gmake
Gmake.c: In function ‘get_lh’:
Gmake.c:111: warning: cast from pointer to integer of different size
Gmake.c:113: warning: cast from pointer to integer of different size
Gmake.c: In function ‘main’:
Gmake.c:211: warning: cast from pointer to integer of different size
Gmake.c:214: warning: cast from pointer to integer of different size
Gmake.c:217: warning: cast from pointer to integer of different size
Gmake.c:219: warning: cast from pointer to integer of different size
Gmake.c:221: warning: cast from pointer to integer of different size
Gmake.c:224: warning: cast from pointer to integer of different size
Gmake.c:227: warning: cast from pointer to integer of different size
gcc -std=gnu99 -O3 -pipe  -gLmake.c   -o Lmake
Lmake.c: In function ‘main’:
Lmake.c:223: warning: cast from pointer to integer of different size
Lmake.c:228: warning: cast from pointer to integer of different size
Lmake.c:230: warning: cast from pointer to integer of different size
Lmake.c:232: warning: cast from pointer to integer of different size
Lmake.c:235: warning: cast from pointer to integer of different size
Converting world to world2
f convert.awk  world.line  world2.line
/bin/bash: f: command not found
make: [world2.line] Error 127 (ignored)
make county.L state.L usa.L nz.L world.L world2.L italy.L france.L
make[1]: Entering directory `/tmp/RtmpssTER5/R.INSTALL21eb6525/maps/src'
./Lmake 0 s b county.line county.linestats ../inst/mapdata/county.L
./Lmake 0 s b state.line state.linestats ../inst/mapdata/state.L
./Lmake 0 s b usa.line usa.linestats ../inst/mapdata/usa.L
./Lmake 0 s b nz.line nz.linestats ../inst/mapdata/nz.L
./Lmake 0 s b world.line world.linestats ../inst/mapdata/world.L
./Lmake 0 s b world2.line world2.linestats ../inst/mapdata/world2.L
Cannot read left and right at line 1
make[1]: *** [world2.L] Error 1
make[1]: Leaving directory `/tmp/RtmpssTER5/R.INSTALL21eb6525/maps/src'
make: *** [ldata] Error 2
ERROR: compilation failed for package ‘maps’
* removing ‘/home/brad/R/x86_64-pc-linux-gnu-library/2.13/maps’
ERROR: dependency ‘maps’ is not available for package ‘mapproj’
* removing ‘/home/brad/R/x86_64-pc-linux-gnu-library/2.13/mapproj’

The downloaded packages are in
‘/tmp/RtmpwXL9El/downloaded_packages’
Warning messages:
1: In install.packages(mapproj, dependencies = T) :
  installation of package 'maps' had non-zero exit status
2: In install.packages(mapproj, dependencies = T) :
  installation of package 'mapproj' had non-zero exit status
 




## Any idea as to why?  this also happens when I try to install the 'maps'
package




--
View this message in context: 
http://r.789695.n4.nabble.com/installation-of-package-mapproj-had-non-zero-exit-status-tp3662940p3662940.html
Sent from the R help mailing list archive at Nabble.com.
[[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] Confusing piece of R code

2011-07-09 Thread B77S
Have you looked at the manual for any of these? 

?get
?sprintf
?assign 
#and so on...




?
Bazman76 wrote:
 
 m0-epxression((4*theta1*theta2-theta3^2)/(2*x*theta3^2)-0.5*theta1*x)
 
 params-all.vars(m0)  this reads all the
 params from m0 so theta1,2 and 3 correct?
 params-params[-which(params==x)]  checks which params are
 multiplied by x?
 np-length(params)
 
 for(i in 1:6){
 esp-get(sprintf(m%d,i-1))what does get do? sprinf
 formats strings? so what is it doinf here?
 assign(sprintf(m%d,i),D(esp,x)) what doeas assign so what
 in sprintf doing and what does D do?
 }
 
 really really confused?
 


--
View this message in context: 
http://r.789695.n4.nabble.com/Confusing-piece-of-R-code-tp3656660p3656824.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] identifying a 'run' in a vector

2011-07-06 Thread B77S
Hi, 

How can I discern which elements in x (see below) are in 'order', but more
specifically.. only the 1st 'ordered run'?
I would like for it to return elements 1:8... there may be ordered values
after 1:8, but those are not of interest.

x - c(1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 45)


Thanks for any suggestions. 




--
View this message in context: 
http://r.789695.n4.nabble.com/identifying-a-run-in-a-vector-tp3650295p3650295.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] identifying a 'run' in a vector

2011-07-06 Thread B77S

well.. the following works, but if you have another idea I am still
interested. 

1:(which(diff(x)!=1)[1])







B77S wrote:
 
 Hi, 
 
 How can I discern which elements in x (see below) are in 'order', but more
 specifically.. only the 1st 'ordered run'?
 I would like for it to return elements 1:8... there may be ordered values
 after 1:8, but those are not of interest.
 
 x - c(1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 45)
 
 
 Thanks for any suggestions.
 

--
View this message in context: 
http://r.789695.n4.nabble.com/identifying-a-run-in-a-vector-tp3650295p3650318.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] identifying a 'run' in a vector

2011-07-06 Thread B77S
Yes Gabor, you definition (a sequence of numbers which each increase by 1
over the prior
number) is what I meant.  Sorry it that was not clear and I thank you and
Joshua for your time and your explanation. 
This should work fine. 




Gabor Grothendieck wrote:
 
 On Wed, Jul 6, 2011 at 7:32 PM, B77S lt;bps0...@auburn.edugt; wrote:
 Hi,

 How can I discern which elements in x (see below) are in 'order', but
 more
 specifically.. only the 1st 'ordered run'?
 I would like for it to return elements 1:8... there may be ordered values
 after 1:8, but those are not of interest.

 x - c(1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 45)


 
 Since the definition of an ordered run is not given we assume that it
 is a sequence of numbers which each increase by 1 over the prior
 number.  If that is not it then you will need to clarify the problem
 definition.
 
 First calculate a logical vector which is TRUE at each position which
 starts a new run.  Note that the first position in x always starts a
 new run even if that run is a singleton so it can be set to TRUE.  The
 remaining elements can be computed using diff as shown.   The
 resulting logical vector is the argument to cumsum below.
 
 Taking the cumulative sum of this logical vector gives a vector the
 same length as x but with each element of the 1st run replaced with 1,
 each element of the 2nd run replaced with 2 and so on.
 
 Finally, since we only want the 1st run we pick out those positions of
 x where the cumsum equals 1.
 
 x[cumsum(c(TRUE, diff(x) != 1)) == 1]
 [1] 1 2 3 4 5 6 7 8
 
 
 -- 
 Statistics  Software Consulting
 GKX Group, GKX Associates Inc.
 tel: 1-877-GKX-GROUP
 email: ggrothendieck at gmail.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.
 

--
View this message in context: 
http://r.789695.n4.nabble.com/identifying-a-run-in-a-vector-tp3650295p3650509.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] Linking 2 columns in 2 databases and applying a function

2011-06-22 Thread B77S
1st of all Dr Utz, thanks for your recent pubs on regional differences
between the piedmont and coastal plain streams.  

and to add to Daniels post (giving your binary yes/no):

df-merge(x,y,all.x=T,all.y=F)

df[exceed] - ifelse(df$Qdf$Threshold_Q , 1, 0)

## now look at df
df





Daniel Malter wrote:
 
 For example, you can merge the two data frames and do a direct comparison:
 
 df-merge(x,y,all.x=T,all.y=F)
 df
 df$Qdf$Threshold_Q
 
 HTH,
 Daniel 
 
 
 Ryan Utz-2 wrote:
 
 Hi all,
 
 I have two datasets, one that represents a long-term time series and one
 that represents summary data for the time series. It looks something like
 this:
 
 x-data.frame(Year=c(2001,2001,2001,2001,2001,2001,2002,2002,2002,2002,2002,2002),
 Month=c(1,1,1,2,2,2),Q=c(5,5,5,6,6,6,3,3,3,4,4,5))
 y-data.frame(Year=c(2001,2001,2002,2002),Month=c(1,2,1,2),Threshold_Q=c(5,5,4,4))
 
 What I'd like to do is link the Year and Month fields in both dataframes
 then determine if Q exceeds Q_Threshold (by noting it with something like
 1
 or 0 in a new field in the dataframe x).
 
 If I were doing this in the more-familiar-to-me Matlab, I'd just write a
 pair of nested for-loops. But as we know, this won't fly in R. I've tried
 reading the help pages and seeking for solutions on the net, with no luck
 (I'm relatively new to R and the help pages are still a bit opaque to
 me).
 It seems like the functions apply or lapply are key, but I can't make
 sense of their syntax.
 
 Any advice/help?!?
 
 Many thanks,
 Ryan
 
 -- 
 
 Ryan Utz, Ph.D.
 Aquatic Ecologist/STREON Scientist
 National Ecological Observatory Network
 
 Home/Cell: (724) 272-7769
 Work: (720) 746-4844 ext. 2488
 
  [[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://r.789695.n4.nabble.com/Linking-2-columns-in-2-databases-and-applying-a-function-tp3617710p3617861.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] automatically generate the output name of my for loops

2011-06-12 Thread B77S
?paste
something like...
paste (group, i, sep=_)



jiliguala wrote:
 
 Hello R users, 
 
 I am new to R and am having difficulty with the output name of my for
 loops. 
 
 here is the problem:
 
 
 for (i in c(1:100))
 {
 the name of the groups - which(k1$cluster==i)
 }
 
 how can it automatically generate the name for 100 cluster(just like
 group_1, group_2...)? what should i put in the bold letter place?
 really thank you for helping me
 
 Daniel
 

--
View this message in context: 
http://r.789695.n4.nabble.com/automatically-generate-the-output-name-of-my-for-loops-tp3592160p3593124.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] automatically generate the output name of my for loops

2011-06-12 Thread B77S
?paste
something like...
paste (group, i, sep=_)



jiliguala wrote:
 
 Hello R users, 
 
 I am new to R and am having difficulty with the output name of my for
 loops. 
 
 here is the problem:
 
 
 for (i in c(1:100))
 {
 the name of the groups - which(k1$cluster==i)
 }
 
 how can it automatically generate the name for 100 cluster(just like
 group_1, group_2...)? what should i put in the bold letter place?
 really thank you for helping me
 
 Daniel
 

--
View this message in context: 
http://r.789695.n4.nabble.com/automatically-generate-the-output-name-of-my-for-loops-tp3592160p3593123.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] scatter plot: multiple Y variables and error bars

2011-05-18 Thread B77S
#Hi all, 
#Using the example data that follows, can someone please show me how to get
a scatterplot of points with #error bars in the Y direction. something like
this works for one Y:

xYplot(Cbind(y1, l1, u1) ~x1,  data=y)

#but  this:

xYplot(Cbind(y1, l1, u1) + Cbind(y2, l2, u2)~x1,  data=y)

# doesn't give me what I would have expected, which is both sets of points
to have their respective error # bars.  Any examples would be greatly
appreciated, and I am not partial to xYplot, so please share #anything you
like. 

y1 - c(1, 1.2, 0.9, 1, 1.2)
u1 - c(1.3, 1.4, 1.3, 1.2, 1.4)
l1 - c(0.8, 0.9, 0.85, 0.8, 0.9)
x1 -  c(1:5)
y2 - c(1.2, 1.4, 1.2, 1.4, 1.5)
u2 - c(1.5, 1.8, 1.6, 1.6, 1.7)
l2 - c(1.1, 1.3, 1.0, 1.2, 1.4)
y - data.frame(y1,u1,l1,x1)


## thanks ahead of time!

--
View this message in context: 
http://r.789695.n4.nabble.com/scatter-plot-multiple-Y-variables-and-error-bars-tp3531563p3531563.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] Clearing Console; of weeks of codes!

2011-04-14 Thread B77S
If you don't want your history, why not just do this.

q()

Save workspace image? [y/n/c]: 

n


??
Am I missing something?
1Rnwb wrote:
 
 Thanks, I thought that removing the list would take care of it. the
 question is I do not see a .Rhistory file in my current working directory,
 so where it is stored. it is not visible in C:\Program files\R either.
 Serarching the C;\ and D:\ drives shows some old .Rhistory files but not
 the recent ones.
 Thanks
 

--
View this message in context: 
http://r.789695.n4.nabble.com/Clearing-Console-of-weeks-of-codes-tp3447506p3449876.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] extract element from list by rownames

2011-04-12 Thread B77S
This probably is not ideal, but this works on a list of mine..

## so you can see the structure of my list
 str(srMT)
List of 4
 $ mode : chr discrete
 $ ks.stat  : chr mean
 $ observed :List of 4
  ..$ filter: num [1:13, 1:4] 0.213 0.207 0.144 0.311 0.24 ...
  .. ..- attr(*, dimnames)=List of 2
  .. .. ..$ ID_2: chr [1:13] BC_SP1 BU1_SP1 BU2_SP1 MK_SP1 ...
  .. .. ..$ : chr [1:4] vel1 vel2 vel3 vel4
  ..$ chi2  : num [1:3] 6.93e+02 6.93e+02 1.93e-12
  ..$ df: num [1:3] 36 39 3
  ..$ p : num [1:3] 0 0 1
 $ bootstrap:List of 6
  ..$ filter   : num [1:13, 1:4, 1:1000] 0.245 0.254 0.247 0.244 0.25 ...
# LIST just keeps going  and going and going


# as an example 

 (srMT[[3]][1])
$filter
 
ID_2   vel1  vel2  vel3  vel4
  BC_SP1  0.2127431 0.1923574 0.2839013 0.3109983
  BU1_SP1 0.2072090 0.3094771 0.2219164 0.2613975
  BU2_SP1 0.1437481 0.3270975 0.2401788 0.2889757
  MK_SP1  0.3114887 0.2503257 0.2177326 0.2204530
  MO_SP1  0.2395539 0.2079802 0.3208321 0.2316338
  MU1_SP1 0.2336137 0.1923791 0.2386081 0.3353991
  MU2_SP1 0.3607257 0.2466847 0.1501613 0.2424284
  MU3_SP1 0.3583597 0.2499569 0.1652739 0.2264095
  RB_SP1  0.2912842 0.2742916 0.1768310 0.2575933
  SB1_SP1 0.2108506 0.2075117 0.3399161 0.2417215
  SB2_SP1 0.2910056 0.2306834 0.2507012 0.2276098
  SB4_SP1 0.2958040 0.2358855 0.2433465 0.2249641
  SC_SP1  0.2509970 0.2129797 0.3071544 0.2288689




## some rownames
b - c(MK_SP1, SB1_SP1, SB4_SP1)

## this works to pull them out based on row names

 data.frame((srMT[[3]][1]))[b,]
filter.vel1 filter.vel2 filter.vel3 filter.vel4
MK_SP10.3114887   0.2503257   0.2177326   0.2204530
SB1_SP1   0.2108506   0.2075117   0.3399161   0.2417215
SB4_SP1   0.2958040   0.2358855   0.2433465   0.2249641




I hope this helps, good luck!






Alfredo Alessandrini wrote:
 
 Hi,
 
 I've a list of list.
 
 I want to extract an element by the rownames.
 
 I can extract it by:
 
 data[[1]][[1]][[4]][1]
 
 
 But I want to exctract it by a command like this:
 
 data[[1]][[B0]][[smac]][[cont]][1]
 
 It's possible?
 
 
 Thanks,
 
 Alfredo
 
 
 
 
 str(data)
 List of 1
  $ :List of 4
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.4 0.458 0.5
   .. ..$ : num [1:41, 1] 0.4 0.403 0.405 0.407 0.41 ...
   .. ..$ : num [1:41, 1] 0.000128 0.000328 0.000528 0.000728 0.000992 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] 0 0 -0.00626 0.99832 0 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.58 0.67 0.782
   .. ..$ : num [1:82, 1] 0.58 0.583 0.585 0.588 0.59 ...
   .. ..$ : num [1:82, 1] 0.0017 0.00168 0.00165 0.00162 0.0016 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.00597 0.71045 -0.05844 0.99187 -0.00807 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.7 0.82 1.03
   .. ..$ : num [1:133, 1] 0.7 0.703 0.705 0.708 0.71 ...
   .. ..$ : num [1:133, 1] 0.0007 0.000775 0.00085 0.000925 0.001 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.030584 0.559164 -0.000269 0.995624
 -0.006616 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 1.45 1.64 1.8
   .. ..$ : num [1:141, 1] 1.45 1.45 1.46 1.46 1.46 ...
   .. ..$ : num [1:141, 1] 0.001 0.001 0.001 0.001 0.001 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.00547 0.65798 0 0 0 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..- attr(*, dim)= int [1:3] 4 1 1
   ..- attr(*, dimnames)=List of 3
   .. ..$ : chr [1:4] B0 B2 B3 MIR
   .. ..$ : NULL
   .. ..$ : NULL

 
 __
 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, 

Re: [R] extract element from list by rownames

2011-04-12 Thread B77S
I'm thinking this isn't what you want.. but also:

 data.frame((srMT[[3]][1]))[b,][2]
filter.vel2
MK_SP10.2503257
SB1_SP1   0.2075117
SB4_SP1   0.2358855




B77S wrote:
 
 This probably is not ideal, but this works on a list of mine..
 
 ## so you can see the structure of my list
 str(srMT)
 List of 4
  $ mode : chr discrete
  $ ks.stat  : chr mean
  $ observed :List of 4
   ..$ filter: num [1:13, 1:4] 0.213 0.207 0.144 0.311 0.24 ...
   .. ..- attr(*, dimnames)=List of 2
   .. .. ..$ ID_2: chr [1:13] BC_SP1 BU1_SP1 BU2_SP1 MK_SP1 ...
   .. .. ..$ : chr [1:4] vel1 vel2 vel3 vel4
   ..$ chi2  : num [1:3] 6.93e+02 6.93e+02 1.93e-12
   ..$ df: num [1:3] 36 39 3
   ..$ p : num [1:3] 0 0 1
  $ bootstrap:List of 6
   ..$ filter   : num [1:13, 1:4, 1:1000] 0.245 0.254 0.247 0.244 0.25 ...
 # LIST just keeps going  and going and going
 
 
 # as an example 
 
 (srMT[[3]][1])
 $filter
  
 ID_2   vel1  vel2  vel3  vel4
   BC_SP1  0.2127431 0.1923574 0.2839013 0.3109983
   BU1_SP1 0.2072090 0.3094771 0.2219164 0.2613975
   BU2_SP1 0.1437481 0.3270975 0.2401788 0.2889757
   MK_SP1  0.3114887 0.2503257 0.2177326 0.2204530
   MO_SP1  0.2395539 0.2079802 0.3208321 0.2316338
   MU1_SP1 0.2336137 0.1923791 0.2386081 0.3353991
   MU2_SP1 0.3607257 0.2466847 0.1501613 0.2424284
   MU3_SP1 0.3583597 0.2499569 0.1652739 0.2264095
   RB_SP1  0.2912842 0.2742916 0.1768310 0.2575933
   SB1_SP1 0.2108506 0.2075117 0.3399161 0.2417215
   SB2_SP1 0.2910056 0.2306834 0.2507012 0.2276098
   SB4_SP1 0.2958040 0.2358855 0.2433465 0.2249641
   SC_SP1  0.2509970 0.2129797 0.3071544 0.2288689
 
 
 
 
 ## some rownames
 b - c(MK_SP1, SB1_SP1, SB4_SP1)
 
 ## this works to pull them out based on row names
 
 data.frame((srMT[[3]][1]))[b,]
 filter.vel1 filter.vel2 filter.vel3 filter.vel4
 MK_SP10.3114887   0.2503257   0.2177326   0.2204530
 SB1_SP1   0.2108506   0.2075117   0.3399161   0.2417215
 SB4_SP1   0.2958040   0.2358855   0.2433465   0.2249641
 
 
 
 
 I hope this helps, good luck!
 
 
 
 
 
 
 Alfredo Alessandrini wrote:
 
 Hi,
 
 I've a list of list.
 
 I want to extract an element by the rownames.
 
 I can extract it by:
 
 data[[1]][[1]][[4]][1]
 
 
 But I want to exctract it by a command like this:
 
 data[[1]][[B0]][[smac]][[cont]][1]
 
 It's possible?
 
 
 Thanks,
 
 Alfredo
 
 
 
 
 str(data)
 List of 1
  $ :List of 4
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.4 0.458 0.5
   .. ..$ : num [1:41, 1] 0.4 0.403 0.405 0.407 0.41 ...
   .. ..$ : num [1:41, 1] 0.000128 0.000328 0.000528 0.000728 0.000992 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] 0 0 -0.00626 0.99832 0 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.58 0.67 0.782
   .. ..$ : num [1:82, 1] 0.58 0.583 0.585 0.588 0.59 ...
   .. ..$ : num [1:82, 1] 0.0017 0.00168 0.00165 0.00162 0.0016 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.00597 0.71045 -0.05844 0.99187 -0.00807
 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 0.7 0.82 1.03
   .. ..$ : num [1:133, 1] 0.7 0.703 0.705 0.708 0.71 ...
   .. ..$ : num [1:133, 1] 0.0007 0.000775 0.00085 0.000925 0.001 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.030584 0.559164 -0.000269 0.995624
 -0.006616 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..$ :List of 4
   .. ..$ : num [1, 1:3] 1.45 1.64 1.8
   .. ..$ : num [1:141, 1] 1.45 1.45 1.46 1.46 1.46 ...
   .. ..$ : num [1:141, 1] 0.001 0.001 0.001 0.001 0.001 ...
   .. ..$ :List of 1
   .. .. ..$ : num [1:49, 1] -0.00547 0.65798 0 0 0 ...
   .. .. ..- attr(*, dim)= int [1:3] 1 1 1
   .. .. ..- attr(*, dimnames)=List of 3
   .. .. .. ..$ : chr cont
   .. .. .. ..$ : NULL
   .. .. .. ..$ : NULL
   .. ..- attr(*, dim)= int [1:3] 4 1 1
   .. ..- attr(*, dimnames)=List of 3
   .. .. ..$ : chr [1:4] begin.mode.end lambda sensi smac
   .. .. ..$ : NULL
   .. .. ..$ : NULL
   ..- attr(*, dim)= int [1:3] 4 1 1
   ..- attr(*, dimnames)=List of 3
   .. ..$ : chr [1:4] B0 B2 B3 MIR
   .. ..$ : NULL
   .. ..$ : NULL

Re: [R] Removing objects and clearing memory

2011-04-12 Thread B77S
#replace v with whatever
rm(list=(ls()[ls()!=v]))


--
View this message in context: 
http://r.789695.n4.nabble.com/Removing-objects-and-clearing-memory-tp3445763p3445865.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] How to create a 3d Surface plot from a CSV file?

2011-04-08 Thread B77S
step # 1
?read.csv

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-create-a-3d-Surface-plot-from-a-CSV-file-tp3437463p3437478.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] How to call data elements

2011-04-06 Thread B77S
assuming this is from a list

mydata[[1]][1]  

and 

mydata[[1]][7]

??




Wonjae Lee wrote:
 
 Hi, 
 
 I have a stupid and simple question. 
 Please forgive me. 
 
 In an example below, please tell me how to call  1947 in mydata. 
 Thank you in advance. 
 
 Wonjae 
 
 mydata 
 [[1]] 
 [1] 194783  234.289 235.6   159 107.608 1947   
 [8] 60.323 
 
 mydata[[1],1] 
 error:unexpected ',' in mydata[[1], 
 mydata[1,[1]] 
 error:unexpected '[' in mydata[1,[
 

--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-call-data-elements-tp3430859p3430881.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] problem with all/all.equal

2011-04-06 Thread B77S
ifelse(length(unique(x))==1, All Equal, Not All Equal)


--
View this message in context: 
http://r.789695.n4.nabble.com/problem-with-all-all-equal-tp3431956p3432167.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] R, Ubuntu, package installation with non-zero exit status

2011-04-06 Thread B77S
FYI:
The problem I had was that my modified .Rprofile text file was being read
and had lines to load the libraries of packages that were not installed yet
on this Ubuntu machine; I guess I copied the .Rprofile from my laptop.
 
If you have similar problems, simply do this in command line:

mv .Rprofile Rprofile

install.packages to your hearts desire and then 

mv Rprofile .Rprofile



--
View this message in context: 
http://r.789695.n4.nabble.com/R-Ubuntu-package-installation-with-non-zero-exit-status-tp3305989p3432176.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] unexpected sort order with merge

2011-04-06 Thread B77S
That is odd, I noticed some weird sorting with merge() a while back too and
always am careful with it now.  Fortunately, sort=FALSE seems to work the
way one would think most of the time.  

Although, the following results seem weird too!  (adding by=date makes it
not sort oddly, regardless of sort=TRUE or FALSE)

 merge(d1, d2, by=date, sort=F)
  date icpn.x foo icpn.y bar
1 Jan 2000500   1500  10
2 Feb 2000500   2500  20
3 Mar 2000500   3500  30
4 Apr 2000500   4500  40
5 May 2000500   5500  50
6 Jun 2000500   6500  60
 merge(d1, d2, by=date, sort=T)
  date icpn.x foo icpn.y bar
1 Jan 2000500   1500  10
2 Feb 2000500   2500  20
3 Mar 2000500   3500  30
4 Apr 2000500   4500  40
5 May 2000500   5500  50
6 Jun 2000500   6500  60
 merge(d1, d2, by=date)
  date icpn.x foo icpn.y bar
1 Jan 2000500   1500  10
2 Feb 2000500   2500  20
3 Mar 2000500   3500  30
4 Apr 2000500   4500  40
5 May 2000500   5500  50
6 Jun 2000500   6500  60
 merge(d1, d2)
  date icpn foo bar
1 Apr 2000  500   4  40
2 Feb 2000  500   2  20
3 Jan 2000  500   1  10
4 Jun 2000  500   6  60
5 Mar 2000  500   3  30
6 May 2000  500   5  50



--
View this message in context: 
http://r.789695.n4.nabble.com/unexpected-sort-order-with-merge-tp3431338p3432250.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] R, Ubuntu, package installation with non-zero exit status

2011-02-14 Thread B77S

All:
I have been looking through the string of posts regarding this same issue,
but I haven't been able to fix this problem. 
I am running Ubuntu 10.4 64bit, R version 2.10.1 
I cannot install certain packages (e.g. vegetarian) and each time it says
basically the same thing (regardless of the package): 

... leaving stuff out ..

Error in library(vegetarian) : there is no package called 'vegetarian'
Execution halted

The downloaded packages are in
‘/tmp/RtmphcJ8mn/downloaded_packages’
Warning message:
In install.packages(vegetarian) :
  installation of package 'vegetarian' had non-zero exit status

###

I have tried the following:
1) ensured I have 'build-essential' Ubuntu package installed (I do)
2) attempted install.packages as root (sudo R)

to no avail
  
-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-Ubuntu-package-installation-with-non-zero-exit-status-tp3305989p3305989.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] R, Ubuntu, package installation with non-zero exit status

2011-02-14 Thread B77S

also, I have 'r-base-dev' installed as well

-- 
View this message in context: 
http://r.789695.n4.nabble.com/R-Ubuntu-package-installation-with-non-zero-exit-status-tp3305989p3306005.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] Need help merging two dataframes

2011-02-11 Thread B77S

## i didn't try this, but I would think it would work

newAB -data.frame(AB$id, AB$age, AB$sex, AB$area)
colnames(newAB)-c(id,age, sex, area) 
uni.newAB - unique(newAB) 
t3-merge(t2, uni.newAB, by=id, all=FALSE) 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Need-help-merging-two-dataframes-tp3297313p3301627.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] Subsampling out of site*abundance matrix

2011-02-08 Thread B77S

It is a lot prettier than mine too.
Thanks Jari.

 rrarefy
function (x, sample) 
{
if (length(sample)  1  length(sample) != nrow(x)) 
stop(length of 'sample' and number of rows of 'x' do not match)
sample - rep(sample, length = nrow(x))
colnames(x) - colnames(x, do.NULL = FALSE)
nm - colnames(x)
for (i in 1:nrow(x)) {
row - sample(rep(nm, times = x[i, ]), sample[i])
row - table(row)
ind - names(row)
x[i, ] - 0
x[i, ind] - row
}
x
}

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3276735.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] Subsampling out of site*abundance matrix

2011-02-07 Thread B77S

Also, I really appreciate you explaining why you used factor.  I'm still not
quite sure what set.seed does (i read ?set.seed) or why you chose 123... but
it and the function below work, so that is all that matters.  :)

randSub - function(L1, s.size)
{
set.seed(123)   
samptbl - apply(L1, 1, function(x) sample(colnames(L1), s.size, prob=x,
replace=TRUE) ) 
sampdf - as.data.frame(samptbl) 
sampdf1 -vector(list)
for(i in 1:nrow(L1))
{   
sampdf1[[i]] -  factor(sampdf[[i]], levels= colnames(L1)) 
}   
out - t(sapply(sampdf1, table)) 
}
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3264251.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] Subsampling out of site*abundance matrix

2011-02-07 Thread B77S

So, after thinking about this a bit, I realized that the previous solution
wasn't exactly what I needed.  I really needed replacement=F and to be able
to choose any sample size (n.sample) less than or equal to the site (row)
with the lowest total abundance.

Anyway, I think this works.  Forgive me if I have misunderstood something
regarding the previous solutions output.  I do not pretend to be
intelligent.Cheers!

### start function ###

RAND_L - function(L.matrix, n.sample){
mainout - vector(list)
for(i in 1:nrow(L.matrix)){
## decomposes species (1:ncol(L.matrix)) into a list of counts per each
out- vector(list)
for(j in 1:length(L.matrix[i,])){
out[[j]] - rep(names(L.matrix[i,])[j], L.matrix[i,j])
}
## puts previous loop products (counts) in a row
out2 - vector()
for(k in 1:length(out)){
out2 - append(out2, as.character(unlist(out[k])))  
}
out3- sample(out2, n.sample, replace=F)
mainout[[i]] - out3
mainout[[i]] - factor(mainout[[i]], levels= colnames(L.matrix))
}
finalout - t(sapply(mainout, table)) 
rownames(finalout)-rownames(L.matrix)  
return(finalout)
}

### end function ## 


 RAND_L(abund2, 100)
  spA spB spC spD spa spF spG
site1  11  12  18   8   0  24  27
site2  24  24   0   0  27  25   0
site3   0   0   6  38   0   0  56
site4  27  20   0   0  16  37   0


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3265402.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] Subsampling out of site*abundance matrix

2011-02-06 Thread B77S

Hello, 
How can I randomly sample individuals within a sites from a site (row) X
species abundance (column) data frame or matrix?  As an example, the matrix
abund2 made below.

# (sorry, Im a newbie and this is the only way I know to get an example
on here)

abund1 -c(150,  300,  0,  360,  150,  300,  0,  240,  150,   0,  60,  
0, 150,  0, 540, 0, 0, 300, 0, 240, 300, 300, 0, 360, 300, 0, 600, 0)
abund2 - matrix(data=abund1, nrow=4, ncol=7)
colnames(abund2) - c(spA, spB, spC, spD, spa, spF, spG)
rownames(abund2)-c(site1, site2, site3, site4) 

#

 abund2
  spA spB spC spD spa spF spG
site1 150 150 150 150   0 300 300
site2 300 300   0   0 300 300   0
site3   0   0  60 540   0   0 600
site4 360 240   0   0 240 360   0

How can I make a random subsample of 100 individuals from the abundances
given for each site?

This is probably really easy.
Thanks.
Bubba 
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3263148.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] Subsampling out of site*abundance matrix

2011-02-06 Thread B77S

I figured there would be an even more straightforward way, but that works
David, thanks.  

There has to be a way to get the output I want/need (see below).  I tried to
bind or merge the elements of apply(samptbl, 2, table) but with no
success.  I could probably make a for loop with a merge statement, it would
work.. but I'm guessing unnecessary and just plain ugly.  

## what I want/need

 spA spB spC spD spa  spF  spG
site1   813   613   320 28
site2   31  25   0  0   25   19  0
site300   9 510 040
site4   27   19  0 022   32  0

If you know, I'd appreciate it.. thanks again for the help. 




David Winsemius wrote:
 
 
 On Feb 6, 2011, at 3:25 PM, B77S wrote:
 

 Hello,
 How can I randomly sample individuals within a sites from a site  
 (row) X
 species abundance (column) data frame or matrix?  As an example, the  
 matrix
 abund2 made below.

 # (sorry, Im a newbie and this is the only way I know to get an  
 example
 on here)

 abund1 -c(150,  300,  0,  360,  150,  300,  0,  240,  150,
 0,  60,
 0, 150,  0, 540, 0, 0, 300, 0, 240, 300, 300, 0, 360, 300, 0, 600, 0)
 abund2 - matrix(data=abund1, nrow=4, ncol=7)
 colnames(abund2) - c(spA, spB, spC, spD, spa, spF, spG)
 rownames(abund2)-c(site1, site2, site3, site4)
 
 Perfect. Best submission of an example by a newbie in weeks.
 

 #

 abund2
  spA spB spC spD spa spF spG
 site1 150 150 150 150   0 300 300
 site2 300 300   0   0 300 300   0
 site3   0   0  60 540   0   0 600
 site4 360 240   0   0 240 360   0

 How can I make a random subsample of 100 individuals from the  
 abundances
 given for each site?
 
 samptbl - apply(abund2, 1, function(x) sample(colnames(abund2), 100,  
 prob=x, replace=TRUE) )
 samptbl
 
 site1 site2 site3 site4
[1,] spG spa spD spF
[2,] spF spF spG spB
[3,] spF spB spC spA
[4,] spD spa spG spA
[5,] spF spa spD spa
[6,] spA spB spD spF
[7,] spA spF spD spA
[8,] spG spF spG spa
[9,] spF spF spG spa
   [10,] spG spB spD spA
 
 Snipped
 
 apply() always transposes the results when called with row margins.  
 The t() function would fix this if it needed to be arranged with  
 rows by site. You could check by further apply-(cation) of table to  
 the columns:
   apply(samptbl, 2, table)
 $site1
 
 spA spB spC spD spF spG
8  13   6  13  32  28
 
 $site2
 
 spa spA spB spF
   25  31  25  19
 
 $site3
 
 spC spD spG
9  51  40
 
 $site4
 
 spa spA spB spF
   22  27  19  32
 

 This is probably really easy.
 
 
 Thanks.
 Bubba
 -- 
 View this message in context:
 http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3263148.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.
 
 David Winsemius, MD
 West Hartford, CT
 
 __
 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://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3263488.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] Subsampling out of site*abundance matrix

2011-02-06 Thread B77S

hehe...
very true sir; I apologize, that was very straightforward.  Thank you for
your time. 


-- 
View this message in context: 
http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3263598.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.