Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread William Michels via R-help
Thank you Jeff for pointing out bad spreadsheet practices in R, seconded by Mathew and Bert. I should have considered creating a second dataframe ("test1_summary") to distinguish raw from processed data. Those who want to address memory issues caused by unnecessary duplication, feel free to chime

Re: [R] Variation of bubble sort (based on divisors)

2017-03-31 Thread Boris Steipe
This looks opaque and hard to maintain. It seems to me that a better strategy is to subset your vector with modulo expressions, use a normal sort on each of the subsets, and add the result to each other. 0 and 1 need to be special-cased. myPrimes <- c(2, 3, 5) mySource <- sample(0:10) # specia

Re: [R] pull stat out of summary

2017-03-31 Thread Bert Gunter
?str tells you the structure of any object. *Learn to use it!* It may well be the that you *cannot* do what you describe. As you should know by now in your "learning curve", invoking > obj at the console silently invokes the print method for obj, and what is printed may in fact be calculated on

Re: [R] pull stat out of summary

2017-03-31 Thread Sarah Goslee
The short answer is that hold isn't a list-like object, and $ only works with list-like objects (lists and data frames, mainly). You can get the full explanation (VERY full), at ?Extract or any of its aliases, like ?'$' or ?'[' Sarah On Fri, Mar 31, 2017 at 7:11 PM, Evan Cooch wrote: > Continui

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Bert Gunter
All: 1. I agree wholeheartedly with prior responses. 2. But let's suppose that for some reason, you *did* want to carry around some "calculated values" with the data frame. Then one way to do it is to add them as attributes to the data frame. This way they cannot "pollute" the data in the way Jef

Re: [R] pull stat out of summary

2017-03-31 Thread David L Carlson
This is your answer: > str(hold) Classes 'summaryDefault', 'table' Named num [1:6] -2.602 0.636 1.514 1.54 2.369 ... ..- attr(*, "names")= chr [1:6] "Min." "1st Qu." "Median" "Mean" ... hold is a table of named numbers, i.e. a vector with a names attribute. It is not a data.frame so it does

[R] Variation of bubble sort (based on divisors)

2017-03-31 Thread Piotr Koller
Hi, I'd like to create a function that will sort values of a vector on a given basis: -zeros -ones -numbers divisible by 2 -numbers divisible by 3 (but not by 2) -numbers divisible by 5 (but not by 2 and 3) etc. I also want to omit zeros in those turns. So when I have a given vector of c(0:1

[R] pull stat out of summary

2017-03-31 Thread Evan Cooch
Continuing my learning curve after 25_ years with using SAS. Want to pull the "Mean" forom the summary of something... test <- rnorm(1000,1.5,1.25) hold <- summary(test) names(hold) [1] "Min.""1st Qu." "Median" "Mean""3rd Qu." "Max." OK, so "Mean" is in there. So, is there a short fo

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Mathew Guilfoyle
This does the summation you want in one line: #create example data and column selection d = as.data.frame(matrix(rnorm(50),ncol=5)) cols = c(1,3) #sum selected columns and put results in new row d[nrow(d)+1,cols] = colSums(d[,cols]) However, I would agree with the sentiments that this is a bad i

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Jeff Newmiller
You can also look at the knitr-RMarkdown work flow, or the knitr-latex work flow. In both of these it is reasonable to convert your data frame to a temporary character-only form purely for output purposes. However, one can usually use an existing function to push your results out without damagin

[R] Deploying R on the cloud - Help Please

2017-03-31 Thread Axel Urbiz
Hello, I work for a large organization who is looking to productionize (deploy) models built in R on the cloud. Currently, we were looking into IBM Bluemix, but I’ve been told only Python is supported for model deployment. I’d appreciate if anyone can point me to the right direction here in terms

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread William Michels via R-help
Again, you should always copy the R-help list on replies to your OP. The short answer is you **shouldn't** replace NAs with blanks in your matrix or dataframe. NA is the proper designation for those cell positions. Replacing NA with a "blank" in a dataframe will convert that column to a "characte

Re: [R] Using R and Python together

2017-03-31 Thread Wensui Liu
In https://statcompute.wordpress.com/?s=rpy2, you can find examples of rpy2. In https://statcompute.wordpress.com/?s=pyper, you can find examples of pyper. On Fri, Mar 31, 2017 at 11:38 AM, Kankana Shukla wrote: > I'm not great at rpy2. Are there any good examples I could see to learn > how to

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread William Michels via R-help
I'm sure there are more efficient ways, but this works: > test1 <- matrix(runif(50), nrow=10, ncol=5) > ## test1 <- as.data.frame(test1) > test1 <- rbind(test1, NA) > test1[11, c(1,3)] <- colSums(test1[1:10,c(1,3)]) > test1 HTH, Bill. William Michels, Ph.D. On Fri, Mar 31, 2017 at 9:20 AM,

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread Berend Hasselman
> On 31 Mar 2017, at 19:28, John McKown wrote: > > On Fri, Mar 31, 2017 at 12:15 PM, Berend Hasselman wrote: > > I have noted a difference between R on macOS en on Kubuntu Trusty (64bits) > with complex division. > I don't know what would happen R on Windows. > > R.3.3.3: > > macOS (10.11.6

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread John McKown
On Fri, Mar 31, 2017 at 12:15 PM, Berend Hasselman wrote: > > I have noted a difference between R on macOS en on Kubuntu Trusty (64bits) > with complex division. > I don't know what would happen R on Windows. > > R.3.3.3: > > macOS (10.11.6) > - > > (1+2i)/0 > [1] NaN+NaNi > > (-1

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread Uwe Ligges
On 31.03.2017 19:15, Berend Hasselman wrote: I have noted a difference between R on macOS en on Kubuntu Trusty (64bits) with complex division. I don't know what would happen R on Windows. R.3.3.3: macOS (10.11.6) - (1+2i)/0 [1] NaN+NaNi (-1+2i)/0 [1] NaN+NaNi 1i/0 [1]

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread William Dunlap via R-help
> dat <- data.frame(Group=LETTERS[1:5], X=1:5, Y=11:15) > pos <- c(2,3) > rbind(dat, Sum=lapply(seq_len(ncol(dat)), function(i) if (i %in% pos) > sum(dat[,i]) else NA_real_)) Group X Y 1 A 1 11 2 B 2 12 3 C 3 13 4 D 4 14 5 E 5 15 Sum 15 65 > str(.Last.val

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread Berend Hasselman
I have noted a difference between R on macOS en on Kubuntu Trusty (64bits) with complex division. I don't know what would happen R on Windows. R.3.3.3: macOS (10.11.6) - > (1+2i)/0 [1] NaN+NaNi > (-1+2i)/0 [1] NaN+NaNi > > 1i/0 [1] NaN+NaNi > 1i/(0+0i) [1] NaN+NaNi KubuntuTru

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Doran, Harold
Let's keep r-list on the email per typical protocol. Apply is a function in base R, so you don't need to install it -Original Message- From: Bruce Ratner PhD [mailto:b...@dmstat1.com] Sent: Friday, March 31, 2017 1:06 PM To: Doran, Harold Subject: Re: [R] Taking the sum of only some col

Re: [R] Using R and Python together

2017-03-31 Thread Kankana Shukla
I'm not great at rpy2. Are there any good examples I could see to learn how to do that? My R code is very long and complicated. On Fri, Mar 31, 2017 at 7:08 AM, Stefan Evert wrote: > > > On 30 Mar 2017, at 23:37, Kankana Shukla wrote: > > > > I have searched for examples using R and Python to

Re: [R] Date operation Question in R

2017-03-31 Thread David Winsemius
> On Mar 30, 2017, at 3:16 PM, Thomas Petzoldt wrote: > > On 30.03.2017 23:34, Paul Bernal wrote: >> Hello everyone, >> >> Is there a way to use the function seq to generate a date sequence in >> this kind of format: jan-2007? > > format(seq(ISOdate(2017,1,1), ISOdate(2017,12,31), "months"), "

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Doran, Harold
Apologies, my code below has an error that recycles the vector x. Hopefully, the concept is clear. -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Doran, Harold Sent: Friday, March 31, 2017 12:34 PM To: 'Bruce Ratner PhD' ; r-help@r-project.org Subject:

Re: [R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Doran, Harold
I do not believe this can be done in one step dat <- data.frame(matrix(rnorm(50), 5)) pos <- c(1,3) res <- apply(dat[, pos], 2, sum) x <- numeric(5) x[pos] <- res rbind(dat,x) -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bruce Ratner PhD Sent:

[R] Taking the sum of only some columns of a data frame

2017-03-31 Thread Bruce Ratner PhD
Hi R'ers: Given a data.frame of five columns and ten rows. I would like to take the sum of, say, the first and third columns only. For the remaining columns, I do not want any calculations, thus rending their "values" on the "total" row blank. The sum/total row is to be combined to the original

[R] conditional regression with mgcv

2017-03-31 Thread Dean Force
Hello, As a part of a larger project, I am trying to run a conditional logistic regression to look at whether maternal age is implicated in the risk of developing gestational diabetes. I am using a matched case-control design, where mothers with GDM were individually matched with up to 6 controls

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread Ista Zahn
The only place I've noticed differences is in encoding and string sorting, both of which are locale and library dependent. Best, Ista On Mar 31, 2017 8:14 AM, "Neil Salkind" wrote: > Can someone please direct me to an answer to the question as to how R > differs for these two operating systems,

Re: [R] fisher.test function error

2017-03-31 Thread Marc Schwartz
> On Mar 31, 2017, at 7:04 AM, Stefan Evert wrote: > > >> On 30 Mar 2017, at 11:51, Eshi Vaz wrote: >> >> When trying to computer a fisher’s exact test using the fisher.test function >> from the gmodels() package, < > > The problem seems to be with a different fisher.test() function fr

Re: [R] fisher.test function error

2017-03-31 Thread peter dalgaard
> On 31 Mar 2017, at 14:04 , Stefan Evert wrote: > > >> On 30 Mar 2017, at 11:51, Eshi Vaz wrote: >> >> When trying to computer a fisher’s exact test using the fisher.test function >> from the gmodels() package, < > > The problem seems to be with a different fisher.test() function from

Re: [R] Using R and Python together

2017-03-31 Thread Stefan Evert
> On 30 Mar 2017, at 23:37, Kankana Shukla wrote: > > I have searched for examples using R and Python together, and rpy2 seems > like the way to go, but is there another (easier) way to do it? Rpy2 would seem to be a very easy and convenient solution. What do you need that can't easily be do

Re: [R] fisher.test function error

2017-03-31 Thread Stefan Evert
> On 30 Mar 2017, at 11:51, Eshi Vaz wrote: > > When trying to computer a fisher’s exact test using the fisher.test function > from the gmodels() package, < The problem seems to be with a different fisher.test() function from the gmodels package, not with stats::fisher.test. The usual r

Re: [R] Difference between R for the Mac and for Windows

2017-03-31 Thread peter dalgaard
File encodings differ when you move outside of standard ASCII code. Not really R's problem, but it is a fly in the ointment when teaching classes with mixed laptop armoury and there are also differences between classroom and desktop computers. RStudio does have features to switch encodings, but