Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Aron Lindberg
Thanks Chuck and Rolf. While Rolf’s code also works on the dput that I actually gave you (a smaller subset of the full dataset), it failed to work on the larger dataset, because there are further exceptions: input[[i]]$content[[1]] is sometimes a list, sometimes a character vector, and

Re: [R] colours in ggplot2

2015-02-20 Thread Thierry Onkelinx
Dear Antonello, You can specify the colours manually with scale_colour_manual(). See http://docs.ggplot2.org/0.9.3.1/scale_manual.html for some examples. The last examples uses greys. Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and

Re: [R] How to analyse nonlinear response to categorical and quantitative explanatory variables?

2015-02-20 Thread Michael Friendly
You want to use a generalized linear model of some sort glm(count ~ flow + gravity + group, data=mydata, family=poisson) would be a start, however, the effects of flow rate are nonlinear, so you might use a natural spline term like ns(flow,5) to allow nonlinearity, and there also seem to be

[R] colours in ggplot2

2015-02-20 Thread Antonello Preti
Hi, I'm using ggplot2 to make a plot of the regression of a variable x (let say, levels of depression), on a variable y (let say, degree of social impairment), by taking into account a binary factor (having had or not a past admission to a psychiatric service), and age of partecipants. After some

Re: [R] multiple parameter optimization with optim()

2015-02-20 Thread Doran, Harold
John et al Thank you for your advice below. It was sloppy of me not to verify my reproducible code below. I have tried a few of your suggestions and wrapped the working code into the function below called pl2. The function properly lands on the right model parameters when I use the optim or

[R] irregular sequence of events

2015-02-20 Thread PIKAL Petr
Dear all I know I am missing something obvious but after few hours of trials I ask for some help. I have some sequence of values (days) x - 1:30 and an indication of event start and end day mimo-c(5,10, 13,16, 21,27) or events - structure(list(start = c(5, 13, 21), end = c(10, 16, 27)),

[R] Design patterns for data munging?

2015-02-20 Thread Aron Lindberg
Hi All, The most difficult challenge that I face in “learning R” is to do data munging. I have reviewed Hadley’s advanced R programming guide, familiarized myself with data structures, subsetting, plyr, dplyr, tidy, the lapply() family of functions, basic string manipulation and grepping, SQL

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Aron Lindberg
Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sha and input[[67]]$content[[1]]$parents[[1]]$sha it’s only the “sha”

Re: [R] irregular sequence of events

2015-02-20 Thread Sarah Goslee
Hi, On Fri, Feb 20, 2015 at 9:27 AM, PIKAL Petr petr.pi...@precheza.cz wrote: Dear all I know I am missing something obvious but after few hours of trials I ask for some help. I have some sequence of values (days) x - 1:30 and an indication of event start and end day mimo-c(5,10,

[R] problem in R

2015-02-20 Thread thanoon younis
Dear all members I have the following matrix in R thd - matrix(testJAGSdata$thd, ncol=6, byrow=TRUE) head(thd) [,1] [,2] [,3] [,4] [,5] [,6] [1,] -200 -2.517 -1.245 -0.444 0.848 200 [2,] -200 -1.447 -0.420 0.119 1.245 200 [3,] -200 -1.671 -0.869 -0.194 0.679 200 [4,] -200

Re: [R] problem in R

2015-02-20 Thread Sarah Goslee
Hi, On Fri, Feb 20, 2015 at 9:48 AM, thanoon younis thanoon.youni...@gmail.com wrote: Dear all members I have the following matrix in R thd - matrix(testJAGSdata$thd, ncol=6, byrow=TRUE) head(thd) [,1] [,2] [,3] [,4] [,5] [,6] [1,] -200 -2.517 -1.245 -0.444 0.848 200 [2,]

Re: [R] multiple parameter optimization with optim()

2015-02-20 Thread Bert Gunter
This is not the proper venue for a discussion of the mathematics of optimization, no matter that it is interesting. Please take it off list. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is

[R] creating a distinct zip file

2015-02-20 Thread Erin Hodgess
Hello yet again. I am trying to create a zip file for a friend who has a Windows machine. He needs to access this via the local zip file packages option. When I use R CMD INSTALL --compile-both, it produces an item in the library tree (as promised). However, I would like to have an actual .zip

Re: [R] irregular sequence of events

2015-02-20 Thread jim holtman
A little shorter version of the SQL solution after consulting with my SQL expert: require(sqldf) timeline - data.frame(time = 1:30) events - structure(list(start = c(5, 13, 21), end = c(10, 16, 27)), .Names = c(start, + end), row.names = c(NA, -3L), class = data.frame) # add event number

Re: [R] Simple Histogram

2015-02-20 Thread JS Huang
Hi, Your data may look like the following and named speed.txt in working directory. Then the cod follows the data. The graph is attached as speed.pdf. Speed 50 52 55 57 58 59 60 61 62 63 64 65 65 65 67 68 68 68 68 69 69 70 71 72 72 72 73 73 73 73 75 76 77 78 79 speed -

[R] running rcorr (Hmisc) on multiple cores

2015-02-20 Thread R Tagett
Hello, I am having trouble generating a correlation matrix on multiple cores. I have a matrix myMat for which I would like to do a Pearson correlation. Lets say dim(myMat) is 100 200. I want a 200x200 correlation matrix and corresponding p-value matrix. I like to use rcorr(myMat) in the

Re: [R] irregular sequence of events

2015-02-20 Thread JS Huang
Hi, Herr is one implementation with function named eventList. start [1] 5 13 21 start [1] 5 13 21 end [1] 10 16 27 x [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 eventList function(start, end, x) { result - character(0) for (i in

[R] Example of Calling a DLL

2015-02-20 Thread Alex Restrepo
All, I'm a newbie to R and am interested in seeing a simple example of calling a 3rd party Visual Studio generated DLL from RStudio. Does anyone have a simple example which also walks through the preliminary steps of setting up the INCLUDE path and the library path to either a DLL or LIB

Re: [R] How do I access a specific element of a multi-dimensional list

2015-02-20 Thread William Dunlap
Using lapply() where Jim used sapply() would keep the types right and be a fair bit faster than a solution based on repeatedly appending to a list (like your getFirst). Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Feb 20, 2015 at 1:52 PM, JS Huang js.hu...@protective.com wrote: Hi,

Re: [R] creating a distinct zip file

2015-02-20 Thread Rolf Turner
On 21/02/15 15:02, Jeff Newmiller wrote: R CMD INSTALL --build packagename That will create a *.tar.gz file, not a *.zip file. The latter being what Erin wanted, if I understand correctly. I have worked around the problem in the past with a shell script like unto: #! /bin/csh set vnum =

Re: [R] How do I access a specific element of a multi-dimensional list

2015-02-20 Thread JS Huang
Hi, Jim's answer is neat. There is an issue on the result. All are characters even though some are numeric or logic. The following implementation retains the variable type. x [[1]] [1] 2 3 5 [[2]] [1] aa bb cc [[3]] [1] TRUE FALSE TRUE getFirst function(aList) { result - list()

[R] Replacing 9999 and 999 values with NA

2015-02-20 Thread Alexandra Catena
Hello All, I have a data frame of two columns for wind. The first column is for wind speed and the second wind direction. I'm trying to replace the values in the first column and the 999 values in the second column with NA. I tried to use the function ltdl.fix.df but it doesn't seem to do

Re: [R] Replacing 9999 and 999 values with NA

2015-02-20 Thread Jeff Newmiller
You did not say how you imported the data, but if you used one of the read.table variants (including read.csv) then you can use the na.strings argument as documented in the help file for read.table. Next time please read the posting guide, as there are some useful tips in there, such as

Re: [R] creating a distinct zip file

2015-02-20 Thread Jeff Newmiller
R CMD INSTALL --build packagename --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go...

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Bert Gunter
How can you expect a solution if you cannot specify the problem? -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Fri, Feb 20, 2015 at 6:13 AM, Aron Lindberg

Re: [R] Averaging column scores when participants vary in number of observations

2015-02-20 Thread John Kane
And just to muddy the waters more here's another way to do it using the handy plyr package where the data.frame is dat1 library(plyr) ddply(dat1, .(Participant.ID), summarize, mean = mean(Score)) John Kane Kingston ON Canada -Original Message- From: js.hu...@protective.com Sent:

Re: [R] Raster Help

2015-02-20 Thread John Kane
Simon, You missed a key request from Sven. He asked for data in dput() format. This is essential for dealing with many problems. Do ?dput for info on the function but esssentially it let's the reader see your data exactly as you see it, unfazed buy any special setting the reader may have for

Re: [R] return named list from foreach

2015-02-20 Thread Jeff Newmiller
You cannot do that in one step. Do it right after: names(out) - df$nm Please don't post using HTML format.. it scrambles code, and since we cannot see what you saw it doesn't help in any way. Also note that df is a function in the base stats package... not a good name to use.

Re: [R] problem in R

2015-02-20 Thread Sarah Goslee
First, please reply to the list, not just me. On Fri, Feb 20, 2015 at 10:22 AM, thanoon younis thanoon.youni...@gmail.com wrote: thank you very much for your help actually, my data set like this #Data Set testJAGSdata = list(N1=200, N2=200, P=18, R=structure(

[R] return named list from foreach

2015-02-20 Thread Alexander Shenkin
Hello all, I've been trying to figure out how to return a named list from foreach. Given that the order of the returned list is guaranteed to be in the order in which the object is passed to foreach, list members can be named afterwards. However, I'm wondering if there's a better way to do

Re: [R] Raster Help

2015-02-20 Thread Simon Tarr
Hi John everyone else, My apologies for not providing you all with a good reproducible example. I will get to work on this and reply in due course. Thanks John for pointing me in the right direction with this. Regards, On 20 February 2015 at 16:06, John Kane jrkrid...@inbox.com wrote:

Re: [R] irregular sequence of events

2015-02-20 Thread jim holtman
Here is a solution using the sqldf package: require(sqldf) timeline - data.frame(time = 1:30) events - structure(list(start = c(5, 13, 21), end = c(10, 16, 27)), .Names = c(start, + end), row.names = c(NA, -3L), class = data.frame) # add event number events$num - paste0(A,

Re: [R] Raster Help

2015-02-20 Thread Simon Tarr
Hi Sven, Many thanks for the reply and my apologies for not posting any code. So far, I have been able to write this (but it's very basic and just getting me to the 'complicated' stage). setwd(C:\\Users\\simon.tarr\\Documents\\GIS\\Test Data) require(raster) require(rgdal)

[R] Issue:CCC Doesn't Match in R and SAS

2015-02-20 Thread sagnik chakravarty
Hi, I was trying to calculate the CCC metric in R with the help of NbClust source code and the available SAS manual for CCC. All the Pseudo-F and R-square are matching exactly with the SAS output except for the E_R2 and hence CCC. I have tried and tested in multiple ways but couldn’t get any

[R] How do I access a specific element of a multi-dimensional list

2015-02-20 Thread Knut Hansen
Dear list, Let's say I have setup the following list: a = c(2, 3, 5) b = c(aa, bb, cc) c = c(TRUE, FALSE, TRUE) x = list(a, b, c) I want to access the first second dimension element of each first dimension element so that the result is something like: (2, aa, TRUE) In my real life problem

[R] Split a dataframe by rownames and/or colnames

2015-02-20 Thread Tim Richter-Heitmann
Dear List, Consider this example df - data.frame(matrix(rnorm(9*9), ncol=9)) names(df) - c(c_1, d_1, e_1, a_p, b_p, c_p, 1_o1, 2_o1, 3_o1) row.names(df) - names(df) indx - gsub(.*_, , names(df)) I can split the dataframe by the index that is given in the column.names after the underscore

Re: [R] How do I access a specific element of a multi-dimensional list

2015-02-20 Thread jim holtman
try this: a = c(2, 3, 5) b = c(aa, bb, cc) c = c(TRUE, FALSE, TRUE) x = list(a, b, c) x [[1]] [1] 2 3 5 [[2]] [1] aa bb cc [[3]] [1] TRUE FALSE TRUE sapply(x, '[[', 1) [1] 2aa TRUE Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you

[R] Windows7, latest R-Studio, newb, how to display 1 column name from a data frame.

2015-02-20 Thread Rod Meriwether
I'm supposed to return for class data with the ID and the value. I'm returning just the correct value. Here's the code and the output. nobs - data.frame() files_list - list.files(directory, full.names=TRUE) dat - data.frame() for (i in id){ dat - (read.csv(files_list[i])) nobs -

Re: [R] Example of Calling a DLL

2015-02-20 Thread Jeff Newmiller
This is off-topic here (read the posting guide). You would probably proceed most effectively by studying how GCC interacts with VS object code, e.g. [1], and studying the Writing R Extensions manual. [1]

Re: [R] creating a distinct zip file

2015-02-20 Thread Jeff Newmiller
On Windows it builds a zip file. If you are on Linux, you might [1] need [2]. [1] https://stat.ethz.ch/pipermail/r-help/2005-January/063596.html [2] http://cran.r-project.org/doc/contributed/cross-build.pdf --- Jeff Newmiller

Re: [R] creating a distinct zip file

2015-02-20 Thread Prof Brian Ripley
On 21/02/2015 07:31, Jeff Newmiller wrote: On Windows it builds a zip file. If you are on Linux, you might [1] need [2]. [1] https://stat.ethz.ch/pipermail/r-help/2005-January/063596.html [2] http://cran.r-project.org/doc/contributed/cross-build.pdf But the first is from 2005 and the second

[R] trouble with .Rd file

2015-02-20 Thread Erin Hodgess
Hello everyone! I've been messing with this .Rd file and am having forest/trees problem by now. Here is the section of the .Rd file that is the troublemaker: \usage{ plot.fore4nodate(y, sim, dates, date.fmt = %Y-%m-%d, gof.leg = FALSE, gof.digits = 2, legend = , leg.cex = 1, bands.col =

Re: [R] trouble with .Rd file

2015-02-20 Thread Duncan Murdoch
On 20/02/2015 12:58 PM, Erin Hodgess wrote: Hello everyone! I've been messing with this .Rd file and am having forest/trees problem by now. Here is the section of the .Rd file that is the troublemaker: \usage{ plot.fore4nodate(y, sim, dates, date.fmt = %Y-%m-%d, gof.leg = FALSE,

[R] Chi-square test

2015-02-20 Thread pari hesabi
Hello, If the vector of observed frequencies is:   f-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11-c(7.577864e-06, 1.999541e-04  ,1.833510e-03,  9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01, 1.525880e-01, 1.689712e-01, 1.563522e-01,   1.232031e-01,

Re: [R] Split a dataframe by rownames and/or colnames

2015-02-20 Thread Bert Gunter
I think ?tapply and friends: ?by ?aggregate ?ave is what you want. -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Fri, Feb 20, 2015 at 9:33 AM, Tim

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Charles C. Berry
On Fri, 20 Feb 2015, Aron Lindberg wrote: Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sha and

Re: [R] Chi-square test

2015-02-20 Thread Berend Hasselman
On 20-02-2015, at 19:05, pari hesabi statistic...@hotmail.com wrote: Hello, If the vector of observed frequencies is: f-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11-c(7.577864e-06, 1.999541e-04 ,1.833510e-03, 9.059845e-03, 2.886977e-02, 6.546229e-02

Re: [R] trouble with .Rd file

2015-02-20 Thread Erin Hodgess
Ah! Perfect. Thanks so much! Sincerely, Erin On Fri, Feb 20, 2015 at 1:03 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 20/02/2015 12:58 PM, Erin Hodgess wrote: Hello everyone! I've been messing with this .Rd file and am having forest/trees problem by now. Here is the

Re: [R] Chi-square test

2015-02-20 Thread David Winsemius
On Feb 20, 2015, at 10:05 AM, pari hesabi wrote: Hello, If the vector of observed frequencies is: f-c(0,0,0,2,3,6,17,15,21,21,14,10,5,1,5) and the vector of probability :p11-c(7.577864e-06, 1.999541e-04 ,1.833510e-03, 9.059845e-03, 2.886977e-02, 6.546229e-02 ,1.124083e-01,

Re: [R] Chi-square test

2015-02-20 Thread David L Carlson
And probably why chisq.test has the rescale.p= argument. Your second problem with small expected values can be handled with simulate.p.value=. chisq.test(f, p=p11) Error in chisq.test(f, p = p11) : probabilities must sum to 1. 1-sum(p11) [1] 4.3036e-08 chisq.test(f, p=p11, rescale.p=TRUE)

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread David Winsemius
On Feb 20, 2015, at 6:13 AM, Aron Lindberg wrote: Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sh and

Re: [R] Split a dataframe by rownames and/or colnames

2015-02-20 Thread David Winsemius
On Feb 20, 2015, at 9:33 AM, Tim Richter-Heitmann wrote: Dear List, Consider this example df - data.frame(matrix(rnorm(9*9), ncol=9)) names(df) - c(c_1, d_1, e_1, a_p, b_p, c_p, 1_o1, 2_o1, 3_o1) row.names(df) - names(df) indx - gsub(.*_, , names(df)) I can split the dataframe

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread William Dunlap
The elNamed(x, name) function can simplify this code a bit. The following gives the same result as David W's get_shas() for the sample dataset provided: get_shas2 - function (input) { lapply(input, function(el) elNamed(elNamed(el, content)[[1]], sha)[1]) } Bill Dunlap TIBCO