[R] Variable selection in clusters using 1-R2 ratio

2017-10-27 Thread Seeliger, Curt
Folks, I am looking for a means for calculating the 1-R^2 ratio for variable selection to mimic the values of PROC VARCLUS in SAS. While there may be better methods for variable selection, we are trying to duplicate published results at this time. To date, I have been unable to find a way to

[R] sendmailR error: if (code == lcode) { : argument is of length zero

2014-08-06 Thread Seeliger, Curt
Good morning folks, Recently calls to sendmail() in the sendmailR package have occasionally failed with the error if (code == lcode) { : argument is of length zero. The only thing we are setting in the control argument is the smtp server (control=list(smtpServer='smtp.epa.gov')), so the port

Re: [R] Syntax for order()

2014-03-25 Thread Seeliger, Curt
dat1[order(val), ] # Gives Error in order(val) : object 'val' not found dat1[order(dat1[,2]), ] # Works just fine. dat1[order(dat1$val), ] unless you used attach(dat1). Better to avoid 'attach' altogether and go with the first suggestion. That can get rather unwieldy when ordering on

Re: [R] Proper Syntax for Logical Subset in Subset()

2011-11-02 Thread Seeliger . Curt
I have measured values for 47 chemicals in a stream. After processing the original data frame through reshape2, the recast data frame has this structure: 'data.frame': 256 obs. of 47 variables: $ site : Factor w/ 143 levels BC-0.5,BC-1,..: 1 1 1 2 2 2 2 2 2 2... $ sampdate :

Re: [R] OT was Re: The elegant way to test if a number is a whole number

2011-09-08 Thread Seeliger . Curt
Oh now wait a minute. If THATs considered old, what's next -- punch cards? CDs? cur - who knows the answers to that question and accepts the mantle of authority conferred by time, though he may not actually live up to it. From: Marc Schwartz marc_schwa...@me.com Oh I knew that Carl?still

Re: [R] How to program with colleagues

2011-04-19 Thread Seeliger . Curt
Alex writes: Dear all, ... a. Do you know if there is any system that can convert our R scripts to html pages with some nice dependency graphs (which functions calls which). b. Could you please suggest me an easy way to exchange the R code with my colleagues. I know about these version

[R] doSMP package works better than perfect, at least sometimes.

2011-04-19 Thread Seeliger . Curt
Some might have noticed that REvolution Computing released the doSMP package to the general public about a month and a half ago, which allows multiple cores to be accessed for parallel computation in R. Some of our physical habitat calculations were taking an extraordinary amount of time to

Re: [R] Removing objects and clearing memory

2011-04-12 Thread Seeliger . Curt
How do I remove all objects except one in R? rm(list=ls()) #will remove ALL objects But he wanted to remove all objects ***except one***!!! So what's the point of this answer? I can't see any way except a rather round-about kludge to do what the OP wants. ... That might work. Or

Re: [R] Geographic distance between lat-long points in R?

2011-04-11 Thread Seeliger . Curt
I have a bunch of geographic locations specified by lat-long coordinates. What's an easy way to calculate geographic distance between any two points? OR, perhaps there is a function for calculating a distance matrix for K sites? A comparison of some geographic distance calculations is

Re: [R] nndist R vs. ArcGIS

2011-04-11 Thread Seeliger . Curt
Alexis wrote: Can anyone tell me why I would get different average nearest neighbor values for the same set of coordinates between ArcGIS 10 and R? Sometimes the difference in distance is over 1.3 km. spatstat::nndist calculates Euclidean distances rather than distances along the earth's

Re: [R] Geographic distance between lat-long points in R?

2011-04-11 Thread Seeliger . Curt
A comparison of some geographic distance calculations is provided at http://pineda-krch.com/2010/11/23/great-circle-distance-calculations-in-r/ , along with code for calculating the Vincenty inverse formula, which relies on the WGS-84 ellipsoid approximations. You know, Scott, I should

Re: [R] Error loop: missing value where TRUE/FALSE needed

2011-02-25 Thread Seeliger . Curt
I often get this error missing value where TRUE/FALSE needed when I'm doing some loops, like with this one ... Can someone explain me what I do wrong because I don't see the difference with other loops that work It's probably not the loop that's biting you, but rather the data. This is

Re: [R] preventing repeat in paste

2011-02-25 Thread Seeliger . Curt
s-start; e-end middle-as.character(c(1,2,3)) I would like to get the following result: start 123 end or start 1 2 3 end or start 1,2,3 end How can I avoide this (undesired) result: paste(s,middle,e,sep= ) Sometimes you just have to do something more than once: paste(s, paste(middle,

Re: [R] aggregate in R

2011-02-22 Thread Seeliger . Curt
Gary/Hongwei writes: I'm wondering how I can aggregate data in R with different functions for different columns. For example: x-rep(1:5,3) y-cbind(x,a=1:15,b=21:35) y-data.frame(y) I want to aggregate a and b in y by x. With a, I want to use function mean; with b, I want to use function

Re: [R] Testing whether a number belong to a set

2011-02-02 Thread Seeliger . Curt
So I was thinking of embedding it into a if else loop but I am stuck on how to define the belongs to in R syntax. Any hint will be much appreciated. ?ifelse# handles vectors, while if() handles single values ?'%in%'# also see match() and which() Enjoy the day, cur -- Curt Seeliger,

Re: [R] Advice on obscuring unique IDs in R

2011-01-05 Thread Seeliger . Curt
Dr. Anthony wrote on 01/05/2011 01:19:49 PM: This may be a question with a really obvious answer, but I can't find it. I have access to a large file with real medical record identifiers (mixed strings of characters and numbers) in it. ... It's not that trivial of a question, or more

Re: [R] Applying function to a TABLE and also apply, tapply, sapply etc

2010-12-15 Thread Seeliger . Curt
Amelia of Aukland writes: Suppose instead of having above dataframe having single data for variable 1 and variable 2, I have following data as variable_1 variable_2 10 20 40 30 3

Re: [R] how to use diff() with different variables?

2010-12-09 Thread Seeliger . Curt
Luca wrote on 12/09/2010 09:38:07 AM: ... What I am trying to do is to build another variable fine1 that should contain the lagged value for fine, that is: xfine fine1 1 A 2010-12-09 07:57:33 NA 2 B 2010-12-09 08:05:00 2010-12-09 07:57:33 3 C 2010-12-08

Re: [R] Delete observations with a frequency x

2010-12-09 Thread Seeliger . Curt
mathijsdevaan wrote on 12/09/2010 04:21:54 PM: I have two columns with data (both identifiers - it's an affiliation list) and I would like to delete the rows in which the observations in the second column have a frequency 5 in the entire second column. Example: 1 a 1 b 1 c

Re: [R] the first. from SAS in R

2010-11-23 Thread Seeliger . Curt
Is there any similar function in R to the first. in SAS? ?duplicated a$d - ifelse( duplicated( a$a ), 0 , 1 ) a$d.2 - as.numeric( !duplicated( a$a ) ) Actually, duplicated does not duplicate SAS' first. operator, though it may suffice for the OP's needs. To illustrate,

Re: [R] the first. from SAS in R

2010-11-23 Thread Seeliger . Curt
... # I've found I need to lag a column to mimic SAS' first. # operator, thusly, though perhaps someone else knows # differently. Note this does not work on unordered # dataframes! lag.k1 - c(NA, tt$k1[1:(nrow(tt) - 1)]) tt$r.first.k1 - ifelse(is.na(lag.k1), 1, tt$k1 != lag.k1)

Re: [R] subsets, %in%

2010-11-05 Thread Seeliger . Curt
Say I need to keep ID 1,2,4,5, 10 from the data frame dat. I can do: dat - data.frame(ID = 1:10, var = 1:10) someID - c(1,2,4,5,10) subset(dat, dat$ID %in% someID) Is there a quick way to do the opposite ... Two operators spring to mind: ! and %nin subset(dat, !(dat$ID %in% someID))

Re: [R] extracting characteristics of datasets from data()

2010-10-25 Thread Seeliger . Curt
Michael writes: I can use data() to find the available datasets in a package, but I'd like to extract and display some additional information for each dataset than what is provided by data(), e.g., class() and dim() for datasets for which these are available. ... for all datasets in

Re: [R] invert order

2010-09-01 Thread Seeliger . Curt
Sebastian writes: I have a huge vector of numbers, how I can invert orden? For example x - 1:1000 I would like to obtain x_r - 1000:1 Well, 1000:1 works for me. If you need to rev()erse a pre-existing vector, try rev(). cur -- Curt Seeliger, Data Ranger Raytheon Information

Re: [R] Linux Editor

2010-08-02 Thread Seeliger . Curt
Is there anything comparable to the mac version of R with its built in console, editor, etc?? Aside from ESS/EMACS, you might try JGR, Tinn-R and Eclipse with StatET. The later has the most features and is the best IDE, and we're in the process of migrating to it from Tinn-R. cur -- Curt

Re: [R] in continuation with the earlier R puzzle

2010-07-12 Thread Seeliger . Curt
The reason R is powerful is becasue it can handle large vectors without each element being manipulated? Please let me know where I am wrong. for(i in 1:length(news1o)){ + if(news1o[i]s2o[i]) + s[i]-1 + else + s[i]--1 + } You might give ifelse() a shot here. s - ifelse(news1o s2o, 1,

Re: [R] SAS for R-users

2010-05-14 Thread Seeliger . Curt
Thomas writes: ... Until then and until I can convince colleagues and teachers to use better software, how do you suggest that I learn SAS? I suspect that it'll be a book on R for SAS-users, so I'm expecting recommendations of books like those that are best for R-users learning SAS. As it

Re: [R] can I rotate a matrix

2010-03-18 Thread Seeliger . Curt
I want to be able to rotate a matrix 90 degrees, clockwise. For example, mat [,1] [,2] [,3] [,1] 12 1 [,2] 32 6 [,3] 45 3 I want to rotate it, so that it looks like this... [,1] [,2] [,3] [,1] 43 1 [,2] 52 2

Re: [R] can I rotate a matrix

2010-03-18 Thread Seeliger . Curt
mat # [,1] [,2] [,3] # [1,]121 # [2,]326 # [3,]453 matrix(rev(mat),nrow=3,byrow=TRUE)[(3:1),] # [,1] [,2] [,3] # [1,]431 # [2,]522 # [3,]361 How's that? (But

Re: [R] two questions for R beginners

2010-02-26 Thread Seeliger . Curt
Patrick Burns pbu...@pburns.seanet.com * What were your biggest misconceptions or stumbling blocks to getting up and running with R? I came into R from SAS, with its powerful data step language and very simplified data types. Most of my work is data manipulation prior to a variety of

Re: [R] Data transformation

2010-01-25 Thread Seeliger . Curt
r-help-boun...@r-project.org wrote on 01/25/2010 02:39:32 PM: x - read.table(textConnection(col1 col2 3 1 2 2 4 7 8 6 5 10), header=TRUE) I want to rewrite it as below: var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 1 0 1 0 0 0 0 0 0

Re: [R] Microsoft SQL Server and R

2010-01-25 Thread Seeliger . Curt
r-help-boun...@r-project.org wrote on 01/25/2010 03:32:41 PM: Jim writes to David: These days I tend to use RJDBC http://www.rforge.net/RJDBC/ which is a bit less of a hassle. Hint use the jtds driver http://jtds.sourceforge.net/ ... I have a client running Microsoft SQL Server. I am

Re: [R] SAS datalines or cards statement equivalent in R?

2009-12-07 Thread Seeliger . Curt
[stuff about SAS CARDS statement, I think] INPUT survey $ 1-2 seasonal $ 3 state $ 4-5 area $ 6-10 supersector $ 11-12 @13 industry $8. datatype $ 21-22 year period $ value footnote $ ; ... This just seems like horrendously bad practice, which is one reason it's kludgy in R. If it

Re: [R] identical(length(x), 1) returns FALSE, but print(length(x)) is 1, length(x)==1 is TRUE, and is.integer(lenght(x)) is TRUE????

2009-09-15 Thread Seeliger . Curt
Corrado writes: I do not understand what more information! Take any vector of length 1, for example x-1. Plus all the command that where in my previous email What is the logic behind identical(length(x),1) being false? identical() returns FALSE because they are not identical,

[R] RUnit detects parse error, but why?

2009-07-10 Thread Seeliger . Curt
Folks, An RUnit test suite is failing after all tests are complete with the following message: Error in parse(n = -1, file = file) : unexpected '}' at 620: 621: } All individual tests work when run individually, and all but one run within the RUnit test suite. What

Re: [R] RUnit detects parse error, but why?

2009-07-10 Thread Seeliger . Curt
An RUnit test suite is failing after all tests are complete with the following message: Error in parse(n = -1, file = file) : unexpected '}' at 620: 621: } ... You need to take a look at the file that was being passed to parse. One way to do this is

[R] Package 'operators'

2009-07-02 Thread Seeliger . Curt
Folks, In brief -- how many of you have found the 'operators' package to be valuable in their work? Not that I lack respect for the amount of work involved in creating and maintaining a package, but I am unsure about the utility of these new operators. Several of the operators appear to

Re: [R] Package 'operators'

2009-07-02 Thread Seeliger . Curt
Thanks for replying, Francois. To directly answer your question, the difference between using base R functions and a library comes down to code correctness and stability, as well as future support. Portions of the language, whether in base or in packages, which have been around a long time,

Re: [R] productivity tools in R?

2009-07-01 Thread Seeliger . Curt
... I saw my friend has a R Console window which has automatic syntax reminder when he types in the first a few letters of R command. ... You might be thinking of JGR (Jaguar) at http://jgr.markushelbig.org/JGR.html . This editor also prompts you with function argument lists, including for

Re: [R] Problem with fractional seconds

2009-05-26 Thread Seeliger . Curt
Thanks for beating me to that, Gabor. The %OS format spec isn't in the strptime() docs. How else might we have found this for ourselves? cur r-help-boun...@r-project.org wrote on 05/26/2009 02:59:20 PM: as.POSIXct(c(06:00:00.100,06:00:01.231), format = %H:%M:%S%OS) [1] 2009-05-26

Re: [R] Problem with fractional seconds

2009-05-26 Thread Seeliger . Curt
Use format, format(myt, %H:%M:%S%OS) -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.c...@epa.gov 541/754-4638 Thanks, that worked. However, is there is way to just get the time and not have the date added? I assume the date is added since POSIX is

Re: [R] Error in importing table from SQL to R

2009-05-21 Thread Seeliger . Curt
Madan asks: I am trying to import a table from SQL server to R(2.9.0), however i am getting errors while running the below codes. Can anyone identify and let me know where did i go wrong??? Thanks in anticipation :) ... NEWDATASQL1 - sqlFetch(myconne, CampaignDataLarge) Error in

Re: [R] How to google for R stuff?

2009-05-20 Thread Seeliger . Curt
Kynn writes: So I'm curious to learn what strategies R users have found to get around this annoyance. I use Rseek for most of my R questions: http://www.rseek.org/ cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.c...@epa.gov 541/754-4638

Re: [R] R-User groups in North America (SF, LA, NYC, Ottawa)

2009-04-22 Thread Seeliger . Curt
Correction: University of Oregon http://www.fsl.orst.edu/R_users - (unknown if currently active) Kenneth B. Pierce Jr. ken.pierce at oregonstate edu That's not University of Oregon, it's Oregon State University. U of O is in Eugene. They don't seem to be recently active in any

Re: [R] Updating a data frame

2009-04-03 Thread Seeliger . Curt
To my earlier question about updating a dataframe, and certainty that this has been solved several times before, Dr. Winsemius suggests (Thanks!): I am sure this is not the most elegant method, but it will work. new - merge(nn,uu, by = c(a,b), all.x=T) new$y - with( new,

[R] Updating a data frame

2009-04-02 Thread Seeliger . Curt
Folks, Updating values in a table is simple in SAS or SQL, but I've wracked my brain looking for an elegant solution in R to no avail thus far. Certainly this is a common need that's been solved in dozens of different ways. Given an initial dataframe nn and a smaller dataframe of updates uu,

[R] R crashes while appending to a created table from SQL Server

2009-03-18 Thread Seeliger . Curt
Folks, The code below reliably crashes an R 2.8.1 session on XP when connected to an SQL Server 2005 database. The problem arises when appending data using sqlSave() with rownames=FALSE to a table that had been previously created with rownames=TRUE. Certainly it's daft to do this as a

[R] RODBC changes data types when reading from MS SQL Server 2005 -- How to fix?

2009-03-17 Thread Seeliger . Curt
Folks, As reproduced in the code below, our data is being transformed during the sqlFetch() operation. This has apparently been an issue since 2002. Are there any ways for correctly reading data from MS SQL Server 2005? Why does RODBC ignore the type information supplied by SQL Server?

Re: [R] ifelse()

2009-02-10 Thread Seeliger . Curt
kayj asks: I have a problem with ifelse(), I do not understand how it works. X-c(2,2,1,1,0,0) str(X) num [1:6] 2 2 1 1 0 0 Y-ifelse(X0,1,0) Y [1] 1 1 1 1 0 0 Since X is a vector, the operation X0 is also a vector. The function ifelse() is correctly providing output for each

[R] aggregate taking way too long to count.

2009-02-10 Thread Seeliger . Curt
Folks, I'm checking the structure of a dataframe for duplicate parameters at a site station (i.e depth should be measured once, not twice), using aggregate to count each parameter within a site station. The fake data below has only 26000 rows, and takes roughly 14 seconds. My real data has

Re: [R] aggregate taking way too long to count.

2009-02-10 Thread Seeliger . Curt
Wow, table() works wonderfully fast! Thank you for pointing it out to me. I still need to associate those counts with specific parameter/station/site combinations, and I'm as stumped by that as I am by the object returned by by(). It looks like I can do the following: tmp - with(df1,

[R] source() argument specification in packages

2008-12-23 Thread Seeliger . Curt
Folks, I am creating a small package which builds just fine but fails the check during the installation phase, as it can not find the files I am source()ing: cannot open file 'c:\PROGRA~1\R\R-28~1.0\library\nla\nlamets.r': No such file or directory The path to the files are predicated on

Re: [R] Logical in test

2008-12-11 Thread Seeliger . Curt
OK, this should be trivial but I'm not finding it. I want to compress the test, if (i==7 | i==10 | i==30 | i==50) {} into something like if (i in c(7,10,30,50)) {} so I can build a excludes vector excludes - c(7,10,30,50) and test if (i in excludes) {} Works for me.

Re: [R] Citing R in journal articles (or the failure to)

2008-11-13 Thread Seeliger . Curt
Could I suggest that citation() be modified to include the URL automatically? I second this suggestion. I experienced similar case once as well. Thanks for pointing that function out to me. When I run it, the URL is included: citation() To cite R in publications use: R Development

Re: [R] Staging area for data before read into R

2008-10-20 Thread Seeliger . Curt
Well, I am going to type in ever value because the data sheets are of counts of insects that I identified, so I should be okay with accuracy... I really just need something that allows for more than 256 columns as I have encounter over 256 species of insects in even small streams. ... Oh,

[R] Interaction between aggregate() and length()

2008-08-28 Thread Seeliger . Curt
Folks, I've been running into an odd situation that occurs when I use length() function with aggregate(), but not with either one separately. Together, the results looks correct but is given an unexpected name. 'if (stringsAsFactors) factor(x) else x' instead of just 'x'. # Numbers work ok

Re: [R] Interaction between aggregate() and length()

2008-08-28 Thread Seeliger . Curt
That's a great work around, as I can eliminate renaming the results column from 'x' to whatever. Thanks for the quick tip, Henrique. On the other hand, I'm still stumped as to why aggregate() would name an output column as 'if (stringsAsFactors) factor(x) else x'. That sort of behaviour