Re: [R] NADA package/cenboxplot() method: maximum censored percentage
Rich, The cenboxplot function uses cenros to estimate the censored values. The cenros function requires at least 2 uncensored observations to be able to do the regression. The cenros function does issue a warning when there are more than 80% censored data, but that is suppressed in cenboxplot. Hope this helps. Dave Date: Wed, 15 Aug 2012 14:28:54 -0700 (PDT) From: Rich Shepard rshep...@appl-ecosys.com To: r-help@r-project.org Subject: [R] NADA package/cenboxplot() method: maximum censored percentage Message-ID: alpine.lnx.2.00.1208151413240.17...@salmo.appl-ecosys.com Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII One set of data has censored (less-than detection limits) water chemistry concentrations for 80-100% of all observations. My initial trial-and-error attempts to apply the cenboxplot() method suggests that it has an upper limit to the percentage of censored observations. I do not see this limit in Dennis Helsel's second edition. Has anyone experience plotting censored data and can provide me with the maximum percentage of censored data in a set of observations? TIA, Rich [[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] R-help Digest, Vol 112, Issue 6
Rich, The documentation for cenboxplot states that the second argument must be logical and not integer. the function cenboxplot substitutes synthetic values for censored values using ros, hence the error message from the ros method. I also do not understand how you expect group = 'SO4' to work. It is not clear that the function will replicate 'SO4' to make a single group. Dave Date: Tue, 5 Jun 2012 09:58:16 -0700 (PDT) From: Rich Shepard rshep...@appl-ecosys.com To: r-help@r-project.org Subject: [R] NADA Applied to my Data Message-ID: alpine.lnx.2.00.1206050931300.27...@salmo.appl-ecosys.com Content-Type: TEXT/PLAIN; format=flowed; charset=US-ASCII I need a nudge in the right direction to get started using NADA. I bought Helsel's second addition and am currently reading it; NADA is installed in R. My data has been restructured with a couple of awk scripts. The data frame structure now has a flag if the quantity is censored (ceneq1 column) as well as a lower and upper limit for censored data. For present purposes, interval censoring can be ignored. The data frame structure is now: str(waterchem) 'data.frame': 46551 obs. of 7 variables: $ site: Factor w/ 126 levels BC-0.5,BC-1,..: 22 22 22 13 3 13 ... $ sampdate: Date, format: 1996-05-22 1996-07-19 ... $ param : Factor w/ 58 levels -0.100,AGP,..: 47 58 10 16 16 26 ... $ quant : num 0.01 7.69 0.02 63.8 120 0.02 399 439 2 433 ... $ ceneq1 : int 1 0 0 0 0 0 0 0 0 0 ... $ low : num 0 7.69 0.02 63.8 120 0.02 399 439 2 433 ... $ high: num 0.01 7.69 0.02 63.8 120 0.02 399 439 2 433 ... What I want to first learn is how to specify a box plot (and whether I can use the lattice package) for specific chemicals. ?cenboxplot shows me the arguments, but I'm not entering them correctly, or there's a prerequisite step I need to take: cenboxplot(waterchem$quant, waterchem$ceneq1, group='SO4', log=T, range=1.5) Error in function (classes, fdef, mtable) : unable to find an inherited method for function ros, for signature numeric, integer Perhaps cenboxplot is looking for a separate data set and not a data frame? Or, perhaps I need to melt and re-cast the data frame to the wide format from the current narrow format? Pointers appreciated. Rich [[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] correlation between XY coordinates
Chris, I think that you really need to quantify what you mean by correlation. Things to consider would depend on what the matrices represent--are they the estimates of the same set of N geographic points, are they traces of the same line, are they traces of the same polygon outline? If either of the latter two, then there would be no reason to believe that they had the same number of points. But the answer to the specific question would dictate how the correlation was computed. Dave below extracted from R-help Digest, Vol 111, Issue 7 Date: Sun, 6 May 2012 08:42:54 -0400 From: Sarah Goslee sarah.gos...@gmail.com To: Christopher Kurby kur...@gvsu.edu Cc: r-help@r-project.org r-help@r-project.org Subject: Re: [R] correlation between XY coordinates Message-ID: 4a58b3c4-c5b6-4c22-a7d3-bd79b8c1f...@gmail.com Content-Type: text/plain; charset=us-ascii Hi Chris, To get a single value you might need something like a Mantel test, available in both ecodist and vegan. That test is a permutation test of significance of the correlation between two distance matrices. Sarah On May 6, 2012, at 8:06 AM, Christopher Kurby kur...@gvsu.edu wrote: Hey Josh (and everyone), My apologies, let me be more specific. I have two sets of XY coordinates in Cartesian space. I would like to compute a correlation between the two sets. For example, let's say I have two N X 2 matrices, with the first column being the X coordinate, the second column being the Y, and with each row being a new observation. I would like to know the strength the relationship between the two sets of coordinates (matrices). cancor provides two separate correlations, but I want a single value representing the strength of the relationship. Is this more clear? Chris On May 5, 2012, at 11:44 PM, Joshua Wiley wrote: Hi Chris, As Jeff mentioned, it is hard to tell what you want (correlations between sets of coordinates could mean many things it seems like to me), but here is something that perhaps helps: ## some data (usually nice if you provide this rather than us having to make something up) d1 - cbind(x - rnorm(100), y - rnorm(100)) d2 - cbind(x2 = x + rnorm(100), y2 = y + rnorm(100)) ## canonical correlation of the two matrices cancor(d1, d2) ## simple correlation matrix of each dataset cor(d1) cor(d2) Cheers, Josh On Sat, May 5, 2012 at 5:32 PM, Christopher Kurby kur...@gvsu.edu wrote: Hello r world, Does anyone know a function or package that can compute correlations between sets of XY coordinates? Thanks in advance for your help, Chris __ 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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Warning on R CMD check
I am trying to check and build a package that requires another package that generates a warning, so the check step never really completes with no warnings. The package uses some routines in the lubridate package, but when the lubridate package is loaded for the check, I get these warnings: Found the following significant warnings: Warning: changing locked binding for '+.Date' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '+.POSIXt' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '-.Date' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '-.POSIXt' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '/.difftime' in 'base' whilst loading 'lubridate' Everything else now checks out OK. Is this a big issue? Can I avoid the error by specifically referring to the functions that I need instead of loading the library? Does the last one cahnge what is specified in the DESCRIPTION file? Thanks. Dave [[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] Warning on R CMD check
Michael, I just checked. I've got 0.2.5. I'll update tonight and see if that fixes the problem. Dave From: R. Michael Weylandt michael.weyla...@gmail.com To: David L Lorenz lor...@usgs.gov Cc: r-help@r-project.org r-help@r-project.org Date: 01/18/2012 03:32 PM Subject: Re: [R] Warning on R CMD check Which version of lubridate do you have on your machine? I don't get those warnings with the current CRAN version 0.2.6: it looks like Hadley changed things to avoid that problem just a few weeks ago: https://github.com/hadley/lubridate/tree/master/R (see the note on zzz.R) Michael On Wed, Jan 18, 2012 at 4:22 PM, David L Lorenz lor...@usgs.gov wrote: I am trying to check and build a package that requires another package that generates a warning, so the check step never really completes with no warnings. The package uses some routines in the lubridate package, but when the lubridate package is loaded for the check, I get these warnings: Found the following significant warnings: Warning: changing locked binding for '+.Date' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '+.POSIXt' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '-.Date' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '-.POSIXt' in 'base' whilst loading 'lubridate' Warning: changing locked binding for '/.difftime' in 'base' whilst loading 'lubridate' Everything else now checks out OK. Is this a big issue? Can I avoid the error by specifically referring to the functions that I need instead of loading the library? Does the last one cahnge what is specified in the DESCRIPTION file? Thanks. Dave [[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. [[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] htest class members and print method
Rui, The answer to your last question is easy--you cannot add a new component to an object of class htest and have it printed by print.htest. But that does not mean that you cannot add a component to the output for your own use. You will need to decide what you want for output, both visually and in terms of ease of any post processing. A data.frame would be nice in that it would already for the table for any report, but it would require that the test you have designed have the same output for all orders. An alternative would be a list that contains the output from each test. Printing the list would create a nicely formatted report for each test. Dave Hello, I am writing a test function, and would like to have it return an appropriate 'htest' object. This is very easy, but the test can be run for several orders, a frequent situation in time series tests. It would be nice to return a data.frame with order, params, test statistic, p.value. After seeing the 'htest' members in the help pages, I discovered that the class has a 'null.value' member that fits the job (it's what I'm using) but it's name may be misleading. Is it possible to create a new member with a new, or at least different, name and have print.htest correctly print it? Rui Barradas [[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.
[R] help for fgui
Anybody use fgui? I find it very handy. I have a question about an argument to the call to gui in the first example. The argument is argFilter, my question has to do with specifying multiple filters. The argument in that example is argFilter=list(flname={{Text files} {.txt}}) ) ## note space inbetween the braces! The problem that I need to solve is that for certain types of files, I may want to have the user choose between a couple of different suffixes or be able to look at all files. Including multiple extensions is easy-- comma separated extensions work. But I can't figure out any way to have the user be able to search first for text files, and if the suffix is not .txt, switch to {Any Files} {*.*}. I am not familiar with tcl, which I assume uses this knid of construct. Any help would be appreciated. Dave [[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] How to get all combinations between two character vectors?
Rainer, The are probably lots of ways, I'd use levels(interaction(c(a, b), c('x', 'y'), sep='')) Dave Hi I know there is a function - I have used it before - but I always forget what it is called... I need the combination of two character vectors, i.e: x - c(a, b) y - c(x, y) z - THEFUNCTION(x, y) z == c(ax, ay, bx, by) I promise I will write the name of the function on my desk! Thanks, Rainer [[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.
[R] Paired data survival analysis, part 2
I'm curious. I've used the paired-prentice Wilcoxon test for the analysis of parried survival data. I haven't run into use of the coxph for that previously, but I have seen it referenced a couple of times in recent web searches. I have a data set of subjects like this: SubjectT1 R1 T2 R2 132 31 228 27 330 31 ... where Subject is the id of the subject, T1 is the test result from test 1, R1 is the remark code ( indicates that the test result is the lower end, right censoring only) and T2 and R2 are the corresponding values for test 2. I would like to know if there is a change from test 1 to test 2. How can I set up the call to coxph for the paired test? Thanks much. Dave From: Terry Therneau thern...@mayo.edu To: Marcus Michelangeli (Sci) marcus.michelang...@monash.edu Cc: r-help@r-project.org Date: 01/25/2011 09:42 AM Subject: Re: [R] Paired data survival analysis Sent by: r-help-boun...@r-project.org --- begin included message --- Im an honours student at Monash University. I'm trying to analyse some data for my project, which involved 2 treatments. My subjects were exposed to both treatments, and i gave them 60 minutes to perform a certain behaviour. 3 of my subjects performed the behaviour in one treatment but not the other. Therefore, i need to do a survival analysis using paired data. Im little confused about how to go about this in R. Im able to perfrom a normal surival analyses not taking the paired data into account, but im just wondering if there is some way to take the pairing into account. I know there are 3 different ways to deal with grouping in the survival package, strata, cluster and frailty but i struggle to understand the meaning of these arguments and therefore do not know which one to use (if any). --- end inclusion --- All 3 methods can be defended. Adding cluster(id) to the model is equivalent to a generalized estimating equations approach (if this were a glm) or to the variance estimates commonly used in survey sampling (if this were a linear model). Adding frailty(id) is equivalent to fitting a linear mixed model. Using strata corresponds to a matched-pair analysis, and will essentially reduce to a sign test: for each subject treatment A was better, B was better, or tied. It's overkill in this case (lower power). If this were a linear model, you could find strong advocates for either the GEE and mixed approach being better. I somewhat prefer the GEE method myself. Terry T. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Saving objects inside a list
Eduardo, Try this: object.list - sapply(objects(), function(x) get(x), simplify=F, USE.NAMES=T) Dave From: Eduardo de Oliveira Horta eduardo.oliveiraho...@gmail.com To: r-help r-help@r-project.org Date: 01/03/2011 11:32 AM Subject: [R] Saving objects inside a list Sent by: r-help-boun...@r-project.org Hello there, any ideas on how to save all the objects on my workspace inside a list object? For example, say my workspace is as follows ls() [1] x y z and suppose I want to put these objects inside a list object, say object.list - list() without having to explicitly write down their names as in object.list$x = x object.list$y = y object.list$z = z Is this possible? Thanks in advance, Eduardo Horta [[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. [[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] Jaccard dissimilarity matrix for PCA
Jacob, You might have a look at the vegan package. It might compute the Jaccard distance and it might have some other toolsa that you might be interested in. Dave From: Flabbergaster jlund...@gmail.com To: r-help@r-project.org Date: 12/28/2010 08:26 AM Subject: [R] Jaccard dissimilarity matrix for PCA Sent by: r-help-boun...@r-project.org Hi I have a large dataset, containing a wide range of binary variables. I would like first of all to compute a jaccard matrix, then do a PCA on this matrix, so that I finally can do a hierarchical clustering on the principal components. My problem is, that I don't know how to compute the jaccard dissimilarity matrix in R? Which package to use, and so on... Can anybody help me? Alternatively I'm search for another way to explore the clusters present in my data. Another problem is, that I have cases with missing values on different variables. Jacob -- View this message in context: http://r.789695.n4.nabble.com/Jaccard-dissimilarity-matrix-for-PCA-tp3165982p3165982.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fitting a Triangular Distribution to Bivariate Data
Dave, I am a little confused. You ask about a triangle distribution, but describe the situation as a relation between y and x. Do you really want a piecewise linear fit of y to x? That could be gotten using nonlinear least squares. Dave From: Jinsong Zhao jsz...@yeah.net To: r-help@r-project.org Date: 12/23/2010 07:53 AM Subject: Re: [R] Fitting a Triangular Distribution to Bivariate Data Sent by: r-help-boun...@r-project.org On 2010-12-23 2:19, David Bapst wrote: Hello, I have some xy data which clearly shows a non-monotonic, peaked triangular trend. You can get an idea of what it looks like with: x-1:20 y-c(2*x[1:10]+1,-2*x[11:20]+42) I've tried fitting a quadratic, but it just doesn't the data-structure with the break point adequately. Is there anyway to fit a triangular or 'tent' function to my data in R? Some sample code would be appreciated; I'm not new to R, but I sometimes have difficulty understanding the model-fitting functions (finally figured out how to extrapolate with predict() today!) Thanks! -Dave Bapst, UChicago Hi, you may try the following code: library(triangle) library(fitdistrplus) summary(fitdist(y, triangle, start = list(a = 1.9, b= 21.1, c = 11.5))) Fitting of the distribution ' triangle ' by maximum likelihood Parameters : estimate Std. Error a -1.47 2.3523724 b 23.627448 1.9804026 c 13.00 0.1107073 Loglikelihood: -62.41994 AIC: 130.8399 BIC: 133.8271 Correlation matrix: a b c a 1. -0.14537297 -0.01203898 b -0.14537297 1. -0.01439500 c -0.01203898 -0.01439500 1. HTH ... Jinsong Zhao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Keeping Leading Zeros, Treating numbers as text
James, How about sprintf('%05d', 210) It works for fixed length id numbers. Dave From: James Splinter james.r.splin...@gmail.com To: R-help@r-project.org Date: 12/21/2010 02:44 PM Subject: [R] Keeping Leading Zeros, Treating numbers as text Sent by: r-help-boun...@r-project.org Hello, I have a data set, with some numerical values, some non-numerical data, my issue is that I need to preserve my ID numbers (numerics) with the leading zeros, but when I import the data into R (it's in .csv format) using the read.csv( ) command, it turns all the ID numbers (Example: 00210) into numbers, removing the leading zeros, so I end up with 210. I tried using the as.is= command on the column that I wanted to treat as text, but it had no effect. Any help would be very much appreciated, Thanks, James [[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. [[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] check for item in vector
CH, How about any: any(Tiger == animal) The function which will tell you the index if any match which(Tiger == animal. You should also look at the match funciton. Dave From: C.H. chainsawti...@gmail.com To: R-help r-help@r-project.org Date: 12/13/2010 08:50 AM Subject: [R] check for item in vector Sent by: r-help-boun...@r-project.org Dear R users, Suppose I have an vector like this: animal - c(Tiger,Panda) I would like to know is there any function that check for the existence of certain item in a vector. e.g. func(Tiger,animal) # check for the existence of Tiger TRUE func(Acacia,animal) #Acacia is not an item of the animal vector FALSE I know that it can be done by for loop. But I would like to know is there any built-in function for that. Thank you very much. CH -- CH Chan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] predict.lm[e] with formula passed as a variable
Thorn, Here's how I do it: retval - list(as.name('lm'), formula=as.formula(paste(Response, ~, Explan, sep='')), data=as.name(Data)) #... optionally add other arguments retval - eval(as.call(retval)) Dave From: Thaler, Thorn, LAUSANNE, Applied Mathematics thorn.tha...@rdls.nestle.com To: r-help@r-project.org Date: 12/13/2010 12:16 PM Subject: [R] predict.lm[e] with formula passed as a variable Sent by: r-help-boun...@r-project.org Dear all, In a function I paste a string and convert it to a formula which I pass to lm[e]. The idea is to write a function which takes the name of the response variable and the explanatory variable and the data frame as an argument and calculates an lm[e]. (see example below) This works fine, but if I want to make a prediction on this model, R complains that the object holding the formula (form) cannot be found. How can I circumvent this problem? I think I've to provide somehow an environment to predict holding the binding for the variable form, such that predict can resolve the variable, but I've no clue how to do this. Help is very much appreciated. BR + thanks, Thorn 8 df - data.frame(x=factor(rep(1:2, each=10)), y=c(rnorm(10), rnorm(10, 10)), z=rep(1:10,2)) test - function(df, resp, x, rf, LM = FALSE) { form - paste(resp, x, sep = ~ ) form - as.formula(form) if (LM) { mod - lm(form, data=df) } else { rand - as.formula(paste(~1, rf, sep = | )) mod - lme(form, data = df, random = rand) } x.new - data.frame(levels(df[[x]])) names(x.new) - x if (LM) predict(mod, x.new) else predict(mod, x.new, level=0) } test(df, y, x, z) Error in eval(expr, envir, enclos) : object 'form' not found 8 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
Andrija, You should be able to extract the data that you want using a call like this (AD substituted for your c) with(AD, tapply(X2, X1, function(x) sort(x, dec=T)[1:5])) That returns a list like this: $`1` [1] 10 9 8 7 6 $`2` [1] 25 24 23 22 21 Just package it the way that you want. Dave From: andrija djurovic djandr...@gmail.com To: r-help@r-project.org Date: 12/10/2010 08:21 AM Subject: [R] (no subject) Sent by: r-help-boun...@r-project.org Hi R-help, I am trying to find a way to select five highest values in data frame according some variable. I will demonstrate: c X1 X2 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 2 11 12 2 12 13 2 13 14 2 14 15 2 15 16 2 16 17 2 17 18 2 18 19 2 19 20 2 20 21 2 21 22 2 22 23 2 23 24 2 24 25 2 25 So I would like to select a rows with higest values of X2 inside X1. Expected result should be: X1 X2 1 10 1 9 1 8 1 7 1 6 2 25 2 24 2 23 2 22 2 21 I first oreded the data frame using c=c[with(c,order(X1,-X2)),] but I need a help to select highes five. It is easy to select when I have just 2 unique values of X1 but what is if I have 500 unique values in X1? Thanks Andrija [[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. [[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] More elegant magnitude method
Jonathan, I'd just return the integer part of the common log: floor(log10(x)) Dave From: Jonathan P Daily jda...@usgs.gov To: r-help@r-project.org Date: 12/07/2010 01:44 PM Subject: [R] More elegant magnitude method Sent by: r-help-boun...@r-project.org I have a need to find the order of number to get a scaling parameter as a power of 10. I have a function that works *so far*, but it is ugly and probably buggy. In the interest of avoiding code-based outliers in my data, I thought I would ask if anyone here has a better way. scl - function(x){ + length(charToRaw(format(trunc(x), scientific = F)))-1} a - 123456789 b - 1E15 c - 12.345 scl(a) [1] 8 scl(b) [1] 15 scl(c) [1] 1 Thanks -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it. - Jubal Early, Firefly __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] extracting P values from lm model
Rosario, The summary function will compute the f-statistic, from which you can compute the attained p-value. Here's a snippet that shows the f-stat. summary(lm(Y ~ X))$fstatistic valuenumdfdendf 34.23125 1.0 8.0 Dave From: Rosario Garcia Gil m.rosario.gar...@genfys.slu.se To: r-help r-help@r-project.org Date: 11/29/2010 09:30 AM Subject: [R] extracting P values from lm model Sent by: r-help-boun...@r-project.org Hello I am trying to get out of an lm model the fstatistics, however after I run the model I write names(Model) and the fstatistic does not appear only these. names(Model) [1] coefficients residuals effects rank fitted.values [6] assignqrdf.residual xlevels call [11] terms model How could I extract the P values? I have run a cbind of 1800 response variables so is not easy to do it by hand. Thanks in advance. Rosario __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] the first. from SAS in R
It all has to do with the precedence of the ! operator. Compare !duplicated(v) + 0 with (!duplicated(v)) + 0 Dave From: Charles C. Berry cbe...@tajo.ucsd.edu To: Dennis Murphy djmu...@gmail.com Cc: r-help@r-project.org Date: 11/23/2010 10:08 AM Subject: Re: [R] the first. from SAS in R Sent by: r-help-boun...@r-project.org On Tue, 23 Nov 2010, Dennis Murphy wrote: Interesting. Check this out: u - sample(c(TRUE, FALSE), 10, replace = TRUE) u [1] FALSE FALSE TRUE FALSE FALSE TRUE FALSE FALSE FALSE FALSE class(u) [1] logical u + 0 [1] 0 0 1 0 0 1 0 0 0 0 0 + u [1] 0 0 1 0 0 1 0 0 0 0 v - rpois(10, 3) !duplicated(v) [1] TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE class(!duplicated(v)) [1] logical !duplicated(v) + 0 [1] TRUE FALSE TRUE TRUE TRUE TRUE FALSE TRUE FALSE TRUE 0 + !duplicated(v) [1] 1 0 1 1 1 1 0 1 0 1 # Now assign !duplicated(v) to an object: w - !duplicated(v) class(w) [1] logical 0 + w [1] 1 0 1 1 1 1 0 1 0 1 w + 0 [1] 1 0 1 1 1 1 0 1 0 1 I can see *what* is going on, but what is the reason for it? I see another notebook entry coming :) See ?Arithmetic and read the paragraph under Details starting 'Logical vectors' Chuck Dennis On Tue, Nov 23, 2010 at 6:12 AM, David Winsemius dwinsem...@comcast.netwrote: On Nov 23, 2010, at 8:33 AM, Joel wrote: Is there any similar function in R to the first. in SAS? What it dose is: Lets say we have this table: a b c 1 1 5 1 0 2 2 0 2 2 0 NA 2 9 2 3 1 3 and then I want do to do one thing the first time the number 1 appers in a and something else the secund time 1 appers in a and so on. so something similar to: if first.a { a$d-1 }else{ a$d-0 } The duplicated function which returns a logical vector with those features can easily be coerced to numeric. df$d - as.numeric(!duplicated(df$a)) I was a bit puzzled about my failure to get coercion by the method which I thought was supposed to work, namely adding 0. df$e - !duplicated(df$a)+0 # does not coerce df$e - 0 + !duplicated(df$a) # pre-adding 0 does coerce Maybe the rules on coercion were amended. -- David This would give me a b c b 1 1 5 1 1 0 2 0 2 0 2 1 2 0 NA 0 2 9 2 0 3 1 3 1 Is there such a function in R or anything similar? thx //Joel -- View this message in context: http://r.789695.n4.nabble.com/the-first-from-SAS-in-R-tp3055417p3055417.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. [[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. Charles C. BerryDept of Family/Preventive Medicine cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.