[R] melt error that I don't understand.

2013-09-06 Thread Nutter, Benjamin
I'm stumped. I have a dataset I want to melt to create a temporal sequence of events for each subject, but in each row, I would like to retain the baseline characteristics. D - structure(list(ID = c(A, B, C, D, E, F, G, H, I, J), AGE = structure(c(68L, 63L, 55L, 64L, 60L,

Re: [R] lmer, p-values and all that

2013-04-03 Thread Nutter, Benjamin
My apologies for coming late into this conversation, but I'm curious about something in your response You use the following code to peform a likelihood ratio test between an lm object and a mer object fm0 - lm(distance~age,data=Orthodont) fm2 -

[R] Comparing dcast and reshape

2012-10-17 Thread Nutter, Benjamin
I'm in the middle of my own little intellectual exercise comparing dcast() and reshape() and have successfully stumped myself. I want to melt() a data frame, then dcast() it into a new form. After doing so, I want to duplicate the process using reshape(). So far, I can do the melt and cast

Re: [R] Comparing dcast and reshape

2012-10-17 Thread Nutter, Benjamin
.   Benjamin Nutter |  Biostatistician   |  Quantitative Health Sciences   Cleveland Clinic  |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 445-1365 -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Wednesday, October 17, 2012 5:18 PM To: Nutter, Benjamin

Re: [R] Opinion: Why I find factors convenient to use

2012-08-20 Thread Nutter, Benjamin
Whether I use stringsAsFactors=FALSE or stringsAsFactors=TRUE tends to rely on where my data are coming from. If the data are coming from our Oracle databases (well controlled data), I import the with stringsAsFactors=TRUE and everything is great. If the data are given to me by a fellow in

Re: [R] Variable labels

2012-07-18 Thread Nutter, Benjamin
I have my own function for doing this that is similar to the one presented below. Others may have other ideas that work better. As a general rule, I would caution against writing out just the label without the variable name. The only reason I see to separate the labels and names is if you

Re: [R] Reading a bunch of csv files into R

2012-05-25 Thread Nutter, Benjamin
For example: myDir - some file path filenames - list.files(myDir) filenames - filenames[grep([.]csv, filenames)] data_names - gsub([.]csv, , filenames) for(i in 1:length(filenames)) assign(data_names[i], read.csv(file.path(myDir, filenames[i])))   Benjamin Nutter |  Biostatistician   |  

Re: [R] R help!

2012-05-03 Thread Nutter, Benjamin
So long as x is a character vector, I tend to use the following for this problem. x - c(12/31/11 23:45, 1/1/12 2:15) x.split - strsplit(x, ) x.date - sapply(x.split, function(y) return(y[1])) x.time - sapply(x.split, function(y) if (length(y) 1) return(y[2]) else NA) x.date [1]

Re: [R] VarCorr procedure from lme4

2012-05-02 Thread Nutter, Benjamin
I've run into this situation and have been able to prevent problems by using lme4::VarCor(...)   Benjamin Nutter |  Biostatistician   |  Quantitative Health Sciences   Cleveland Clinic  |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 445-1365 -Original Message- From:

Re: [R] multiple values in one column

2012-04-06 Thread Nutter, Benjamin
This is a function I use for these kinds of situations. Assuming the delimiter within the column is consistent and the spelling is consistent, it is pretty useful. The function returns a vector of 0/1 values, 1 if the text in level is found, 0 otherwise. var=the variable level=The value of

[R] Reading Text Files with RODBC

2012-02-16 Thread Nutter, Benjamin
I'm thoroughly stumped. I've been playing with RODBC and wanted to see if I could retrieve data from text files using this package as well (for the most part, this is an intellectual exercise, but occasionally I do get data files large enough in CSV format RODBC could be helpful) . I set up a

Re: [R] Reading Text Files with RODBC

2012-02-16 Thread Nutter, Benjamin
-Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Thursday, February 16, 2012 1:15 PM To: Nutter, Benjamin Cc: r-help@r-project.org Subject: Re: [R] Reading Text Files with RODBC On Thu, Feb 16, 2012 at 10:12 AM, Nutter, Benjamin nutt...@ccf.org wrote: I'm

Re: [R] R not recognizing words

2012-01-06 Thread Nutter, Benjamin
I've developed a preference for x$y %in% Low when subsetting.   Benjamin Nutter |  Biostatistician   |  Quantitative Health Sciences   Cleveland Clinic  |  9500 Euclid Ave.  |  Cleveland, OH 44195  | (216) 445-1365 -Original Message- From: r-help-boun...@r-project.org

Re: [R] nice report generator?

2011-12-07 Thread Nutter, Benjamin
With any sort of reproducible report, you'll have to 'manually place' all of the tables and figures at least once. If done well, however, you'll only have to ever do it once. I'm not an Sweave expert (yet, regrettably), but using lazyWeave, you could generate a customized ANOVA table using

[R] Loading an S object into R

2011-05-24 Thread Nutter, Benjamin
I hope you'll all forgive me for displaying my severe lack of knowledge on this topic, and I can't really provide much in the way of reproducible code. A colleague of mine has asked if I know how to import an S object into R. The object is stored in a file named 'pre3.f' When I open the file

Re: [R] Loading an S object into R

2011-05-24 Thread Nutter, Benjamin
, May 24, 2011 12:20 PM To: Nutter, Benjamin Cc: r-help@r-project.org Subject: Re: [R] Loading an S object into R Hi Benjamin, I also have no experience with S plus, but the suggestions on the R Import/Export manual seem worth trying: http://cran.r-project.org/doc/manuals/R-data.html#EpiInfo

Re: [R] help with \ in strings

2011-04-25 Thread Nutter, Benjamin
Depending on what else you're writing around the %, you might consider using the latexTranslate() function in Hmisc. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of viostorm Sent: Sunday, April 24, 2011 8:48 AM To:

Re: [R] Fibonacci

2011-04-20 Thread Nutter, Benjamin
Fibonacci - c(1, 1) while (max (Fibonacci) 500){ Fibonacci - c(Fibonacci, sum(tail(Fibonacci, 2))) } -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Georgina Imberger Sent: Wednesday, April 20, 2011 5:43 AM To:

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

2010-11-29 Thread Nutter, Benjamin
My apologies for coming to the party so late. I'm sure this question has been answered a couple of times. The attached function is one I pulled from the help archives, but I can't seem to duplicate the search that led me to it. In any case, I've attached the function I found, and an .Rd file I

Re: [R] Tinn-R looses connection to R (Windows Vista)

2010-11-17 Thread Nutter, Benjamin
I've noticed it, but I haven't looked into it much since I rarely work on Vista. I have found that opening R before I open Tinn-R tends to work better than using Tinn-R to open the preferred GUI. Benjamin -Original Message- From: r-help-boun...@r-project.org

Re: [R] Opening a .R file with R (Windows)

2010-09-30 Thread Nutter, Benjamin
Here's a thread that has some good discussion on the topic http://r.789695.n4.nabble.com/Running-script-with-double-click-td1579014.html -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Tuesday, September 28, 2010

Re: [R] Converting date format

2010-03-23 Thread Nutter, Benjamin
If x is your vector of character date variables: orig.date - as.Date(x, format=c(%m/%d/%Y)) new.date - format(x, format=c(%m/%d/%y)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Hosack, Michael Sent: Tuesday, March 23, 2010

[R] Retrieving latitude and longitude via Google Maps API

2010-03-16 Thread Nutter, Benjamin
Does anyone have any experience retrieving latitutde and longitude for an address from the Google Maps API? I'd like to have an R script that submits a street address, city, state, and zip code and returns the coordinates. So far, I've been submitting the coordinates from another program, then

Re: [R] Help on getting help from manuals

2010-03-12 Thread Nutter, Benjamin
As has been pointed out, there are tools in R to help find the commands you are looking for. As a practical note, I recommend starting with '?' if you think you know what command you need. If you're unsure of what command you need, my next step would be help.search(). Often, the results from

Re: [R] Row-wisely converting a data frame into a list

2010-03-02 Thread Nutter, Benjamin
as.data.frame(t(df)) For example x - as.data.frame(t(mtcars)) typeof(x) [1] list -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sebastian Bauer Sent: Tuesday, March 02, 2010 8:12 AM To: r-help@r-project.org Subject: [R]

Re: [R] counting the number of ones in a vector

2010-02-26 Thread Nutter, Benjamin
What you did works well. You could also try the following. table(x)[1] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Randall Wrong Sent: Friday, February 26, 2010 9:41 AM To: r-help@r-project.org Subject: [R] counting the

Re: [R] counting the number of ones in a vector

2010-02-26 Thread Nutter, Benjamin
But if x has any missing values: x - c(1, 1, 1, NA, NA, 2, 1, NA) sum( x == 1) [1] NA sum(x==1, na.rm=TRUE) [1] 4 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Henrique Dallazuanna Sent: Friday, February 26, 2010 9:47

Re: [R] First. Last. Data row selection

2010-02-23 Thread Nutter, Benjamin
I've attached some functions I've written based on previous questions that have been posted here. Unfortunately, I was too lazy to give credit to previous commenters in my Rd file, and for that I hope they'll forgive me. In any case, please be assured that the functions I've attached are in no

[R] Circles around letters or numbers in plot title

2010-02-23 Thread Nutter, Benjamin
Has anyone ever tried putting a circle around a letter or a number in a plot title? For instance, if I have a plot title Scatterplot for Subject 24, I want to put a circle around 24 to distinguish that plot from the other 30 I've generated. Any tips or ideas beyond plotting a circle in the

Re: [R] all possible subsets, with AIC

2010-02-15 Thread Nutter, Benjamin
I've dabbled in this a little bit, and the result of my dabbling is attached. I'll give you fair warning, however. The attached function can take a long time to run, and if your model has 10 or more predictors, you may be retired before it finishes running. In any case, it will models for all

Re: [R] Drop last numeral

2010-01-12 Thread Nutter, Benjamin
Data-c(1131, 1132, 1731 ,1732 ,1821 ,1822, 2221 ,, 2241 ,2242,414342 ,414371 ,414372) Bldgid-substring(as.character(Data),1,nchar(Data)-1) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of LCOG1 Sent: Tuesday, January 12, 2010

Re: [R] %d/%m/%Y can not be displayed in a .rd file

2010-01-07 Thread Nutter, Benjamin
Try \%d/\%m/\%Y Escaping the % should do the trick. If I remember correctly, Latex uses the % as the comment delimiter. I don't know if that's the cause of the error, but escaping it has always solve the problem for me. -Original Message- From: r-help-boun...@r-project.org

Re: [R] Newbie needs to count elements in a row

2009-12-29 Thread Nutter, Benjamin
For a single row where mat is your matrix and r is the row sum(!is.na(mat[r,])) For every row in the matrix rowSums(!is.na(mat)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Verena Weber Sent: Tuesday, December 29, 2009

Re: [R] Remove double quotation marks

2009-12-29 Thread Nutter, Benjamin
It seems from your example that you're assuming all of the vectors have the same length. If this is the case, then a data.frame might be your friend. df - data.frame( v1 = c(0, 1, 0), v2 = c(1, 1, 0), v3 = c(2, 1, 2), v4 = c(2, 2, 1), v5 = c(0, 1, 1) ) x - 5 get.var -

Re: [R] extracting the last row of each group in a data frame

2009-11-17 Thread Nutter, Benjamin
I usually use the following function: last.record - function(data, id, ..., na.last=TRUE, decreasing=FALSE){ #*** Make vector of variables to sort by v - c(id, unlist(list(...))) #*** Sort Data Frame data - data[do.call(order, c(data[,v, drop=FALSE], na.last=na.last,

Re: [R] row selection

2009-10-09 Thread Nutter, Benjamin
sub3 - x[-seq(1, nrow(x), by=5), ] Notice the '-' in front of the seq() command. This will select everything but what is in the sequence. From: Ashta [mailto:sewa...@gmail.com] Sent: Friday, October 09, 2009 12:42 PM To: Nutter, Benjamin Cc: r-help@r

Re: [R] Drawing lines in margins

2009-07-29 Thread Nutter, Benjamin
Look at the xpd option in ?par. If you set par(xpd=TRUE) you should be able to add a segment for what you want. But please let me know if someone gives you a better way to do this. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of

Re: [R] numbers on barplot

2009-07-27 Thread Nutter, Benjamin
The only thing you're missing is the midpoints of the bars. Since you specified Graph - barplot(dat$Average) You can get the midpoints from the Graph object. So to put the number on top of each bar you might use something like: text(Graph, dat$Average, dat$Average) -Original

Re: [R] help with as.numeric

2009-05-15 Thread Nutter, Benjamin
as.numeric() doesn't convert factors to the explicit value, nor should it. Under what you're expecting, ff you have a factor where the levels are Female and Male, using as.numeric() wouldn't produce anything meaningful. However, as.numeric() does something much smarter. It converts Female to 1,

Re: [R] Help with a cumullative Hazrd Ratio plot

2009-05-13 Thread Nutter, Benjamin
?mtext You may need to adjust the margins. For this I recommend adjusting that mar option in par (see ?par). -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bernardo Rangel Tura Sent: Wednesday, May 13, 2009 6:31 AM To: r-help

Re: [R] Selecting all rows of factors which have at least one positive value?

2009-04-02 Thread Nutter, Benjamin
x - data.frame(matrix(c(rep(11,4),rep(12,3),rep(13,3),rep(0,3),1,rep(0,4),re p(1,2)),ncol=2)) id.keep - unique(subset(x,X20)$X1) x2 - subset(x,X1 %in% id.keep) x2 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Stephan Lindner

Re: [R] adding matrices with common column names

2009-03-27 Thread Nutter, Benjamin
Shucks, Dimitris beat me to it. And his code is a bit more elegant than mine. But since I did the work I may as well post it, right? This version incorporates a couple of error checks to make sure all your arguments are matrices with the same number of rows. add.by.name - function(...){ args

Re: [R] Plot inside For loop

2009-03-25 Thread Nutter, Benjamin
I understood this to mean you want to open a new plotting window on each iteration of the loop. If this is correct, I usually go about it by using x11() If you're looking to add additional lines or points, then you may want to look at the aptly named functions lines() and points(). If neither

Re: [R] Plot inside For loop

2009-03-25 Thread Nutter, Benjamin
To: Nutter, Benjamin Cc: r-help@r-project.org Subject: Re: [R] Plot inside For loop basically the for loop goes something like this setCounters(135); for(i in 1:query) { plot(c2data[start1:count,],c3data[start1:count,],xlim=c(-30,100), ylim=c(-30,90), sub=i); points(..); #count increments

Re: [R] help with loop

2009-03-12 Thread Nutter, Benjamin
Why use a loop? Try using diff() x - c(4, 19, 21, 45, 50, 73, 78, 83, 87, 94) sum(diff(x)) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Rafael Moral Sent: Thursday, March 12, 2009 9:04 AM To: r-help@r-project.org Subject: [R]

Re: [R] The Origins of R

2009-02-04 Thread Nutter, Benjamin
snip Those of us on this list (with the possible exception of one or two nutters) would take it that it goes without saying that R was developed on the basis of S --- we all ***know*** that. snip Just want to clarify that the nutters referred to here are not the same as the Nutters that

Re: [R] parsing problem

2009-02-02 Thread Nutter, Benjamin
-Original Message- From: Nutter, Benjamin Sent: Monday, February 02, 2009 7:37 AM To: 'venkata kirankumar' Subject: RE: [R] parsing problem This is how I would approach it. I'd be happy to know if there's a better way. #*** Initial Data Frame x - c(Kontrolle,Placebo,125mg/kg,250mg/kg

Re: [R] Text data

2009-01-28 Thread Nutter, Benjamin
Jim's solution is more elegant than the following (and probably more efficient) but you could also try the following (This let's you sort by AN/HN, and then by the number at the start of the filename): text - c( 26M_AN_C.bmp, 22M_AN_C.bmp, 20M_HA_O.bmp, 20M_AN_C.bmp, 26M_HA_O.bmp,

Re: [R] help

2009-01-14 Thread Nutter, Benjamin
?floor -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zahid khan Sent: Wednesday, January 14, 2009 8:34 AM To: r-h...@stat.math.ethz.ch Subject: [R] help Dear ALL suppose x=7.5,and i need of only integer part of variable x that

Re: [R] Colors in barplot

2008-12-04 Thread Nutter, Benjamin
I believe the defaults in barplot are found using grey.colors{GrDevices}. ?grey.colors (For some reason my machine won't pull up the help files for grey.colors from the command line, but I can still access it through the html help). -Original Message- From: [EMAIL PROTECTED]

Re: [R] Changing the position of the origin

2008-11-18 Thread Nutter, Benjamin
If I understand what you're seeking to do, you might also consider the rplot() function written by Rolf Turner. It can be found at http://tolstoy.newcastle.edu.au/R/help/02a/1174.html Benjamin -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Plantky

Re: [R] Is there a way to vectorize this? [with correction]

2008-10-31 Thread Nutter, Benjamin
** Sorry to repost. I forgot to include a function necessary to make the example work ** I apologize up front for this being a little long. I hope it's understandable. Please let me know if I need to clarify anything. Several months ago I wrote a series of functions to help me take my R

Re: [R] Standard deviation for rows

2008-10-15 Thread Nutter, Benjamin
?apply e.g. apply(matrix,1,sd) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Alex99 Sent: Wednesday, October 15, 2008 1:17 PM To: r-help@r-project.org Subject: [R] Standard deviation for rows Hi everyone, I have just started using R, and I have a

Re: [R] Reading Data

2008-10-07 Thread Nutter, Benjamin
Perhaps it would be easier to try something like this: df1 - read.table(filename, ... ) # All columns read as characters df1 - t(df1) # Transpose df1 write.table - (df1, newfile, ...) # Write the transposed data # to a new file df2 -

Re: [R] lsmeans

2008-09-26 Thread Nutter, Benjamin
I hope you'll forgive me for resurrecting this thread. My question refers to John Fox's comments in the discussion of lsmeans from https://stat.ethz.ch/pipermail/r-help/2008-June/164106.html John you said, It wouldn't be hard, however, to do the computations yourself, using the coefficient

Re: [R] Coefficients, OR and 95% CL

2008-09-23 Thread Nutter, Benjamin
You might also consider ?confint -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jorge Ivan Velez Sent: Monday, September 22, 2008 5:36 PM To: Luciano La Sala Cc: R mailing list Subject: Re: [R] Coefficients, OR and 95% CL Dear Luciano, See

Re: [R] HI

2008-09-16 Thread Nutter, Benjamin
Perhaps a simpler way might be to use the na argument in read.table. for instance: read.table( filename, na=0, ...) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Amit Patel Sent: Tuesday, September 16, 2008 9:32 AM To: r-help@r-project.org Subject:

Re: [R] Color of box frame in Legend (Was: Matrix barplot)

2008-07-28 Thread Nutter, Benjamin
Try sourcing in the 'new.legend' function below. It's the legend function with a new argument called 'box.col'. The argument will change the color of the box surrounding the legend. If I understand what it is you are looking for, this should work. Also, I didn't see a way to change the axis bar

Re: [R] Simple... but...

2008-07-23 Thread Nutter, Benjamin
x - c(1,3,5) y - c(2,4,6) xy - sort(c(x,y)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: Wednesday, July 23, 2008 8:55 AM To: [EMAIL PROTECTED] Subject: [R] Simple... but... Hi R, If x=c(1,3,5) y=c(2,4,6)

Re: [R] Bland-Altman method to measure agreement with repeated measures

2008-07-07 Thread Nutter, Benjamin
The function given below is one I've written to handle repeated measures. I've also included the Help File. If you happen to see any potential improvements, I would be open to suggestions. ### ### Function Code ### 'Bland.Altman' - function(x,y,alpha=.05,rep.meas=FALSE,subject,...){

Re: [R] [Possible SPAM] Reading selected lines in an .html file

2008-06-05 Thread Nutter, Benjamin
I've tried to tackle a similar question at the request of a coworker. Unfortunately, it is difficult to read in HTML code because it lacks character that can consistently be used as a delimiter. The only guideline I can offer is that any text you're interested in is going to be between a and a .

Re: [R] How do I import packages with the package I've built?

2007-11-19 Thread Nutter, Benjamin
in the survival package will work within my functions even without explicitly loading the package? Thanks for the help. Benjamin -Original Message- From: Uwe Ligges [mailto:[EMAIL PROTECTED] Sent: Saturday, November 17, 2007 12:04 PM To: Nutter, Benjamin Cc: [EMAIL PROTECTED] Subject: Re