[R] Help -- feed data frames, returned from function into list --

2016-03-09 Thread Sunny Singha
Hi, I got a problem. Using loop, I'm trying to feed data frames, returned from the function, into the list but not all data frames are getting captured. I have vector with some string values which I want to pass to the function. *groups* <- c('cocacola', 'youtube','facebook) for(i in 1:length(gr

Re: [R] replace text by uniqe number

2016-03-09 Thread Jim Lemon
Hi Ragia, If you have read in your data frame with read.table or similar and not specified stringsAsFactors=FALSE, the two columns will already be factors. However, unless they both contain the same number of unique values, the numbers associated with those levels won't be the same. Probably the ea

Re: [R] group by rows

2016-03-09 Thread Jim Lemon
Hi carol, You could use the "I" function, which will just return what you pass to it. Jim On Thu, Mar 10, 2016 at 12:28 AM, carol white via R-help wrote: > What should be FUN in aggregate as no function like mean, sum etc will be > applied > Carol > > On Wednesday, March 9, 2016 1:59 PM, S

Re: [R] extracting months from a data

2016-03-09 Thread William Dunlap via R-help
How much do you care about dealing with misformatted date strings, like "111-Oct" or "12-Mai"? Flagging those may be more important than milliseconds of CPU time. Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 9, 2016 at 5:24 PM, Dalthorp, Daniel wrote: > How about the following, whi

Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
How about the following, which is both faster and simpler than either the as.Date(...) or sub(...) solutions discussed earlier: substring(x,first=nchar(x)-2) require(microbenchmark) microbenchmark(format(as.Date(paste0(x,"-2016"),format='%d-%b-%Y'),'%b')) # 59.3 microseconds on my computer microb

Re: [R] extracting months from a data

2016-03-09 Thread Jeff Newmiller
How about slower? That is objective. I use dates all the time so I am quite familiar with what they are good for. However, I prefer to avoid inventing information such as which year the date should have included unless I have to based on knowledge of the data source. It is not good to mislead

Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
Good point about 29-Feb...fixed in the following: format(as.Date(paste0(x,"-2016"),format='%d-%b-%Y'),'%b') # Also: The date functions can be used to easily calculate passage of time and offer good flexibility for formatting output. -Dan P.S. "harder to understand" is in the eye of the beholder

Re: [R] extracting months from a data

2016-03-09 Thread Jeff Newmiller
Still not recommended. That takes more steps, is harder to understand, and will break when given "29-Feb" as input. -- Sent from my phone. Please excuse my brevity. On March 9, 2016 4:15:31 PM PST, "Dalthorp, Daniel" wrote: >Or: > >x <- c( "3-Oct", "10-Nov" ) >format(as.Date(paste0(x,rep("-19

Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
Or: x <- c( "3-Oct", "10-Nov" ) format(as.Date(paste0(x,rep("-1970",length(x))),format='%d-%b-%Y'),'%b') # the 'paste0' appends a year to the text vector # the 'as.Date' interprets the strings as dates with format 10-Jun-2016 (e.g.) # the 'format' returns a string with date in format '%b' (which

Re: [R] extracting months from a data

2016-03-09 Thread Dalthorp, Daniel
?as.Date On Wed, Mar 9, 2016 at 10:14 AM, KMNanus wrote: > I have a series of dates in format 3-Oct, 10-Oct, 20-Oct, etc. > > I want to create a variable of just the month. If I convert the date to a > character string, substr is ineffective because some of the dates have 5 > characters (3-Oct

Re: [R] extracting months from a data

2016-03-09 Thread Jeff Newmiller
Your dates are incomplete (no year) so I suggest staying away from the date functions for this. Read ?regex and ?sub. x <- c( "3-Oct", "10-Nov" ) m <- sub( "^\\d+-([A-Za-z]{3})$", "\\1", x ) -- Sent from my phone. Please excuse my brevity. On March 9, 2016 10:14:25 AM PST, KMNanus wrote: >I h

Re: [R] replace text in table R?

2016-03-09 Thread David Winsemius
> On Mar 8, 2016, at 1:48 PM, Sarah Goslee wrote: > > Thanks for the complete reproducible example. > > Here's one way to approach the problem; there are many others. > > recodeDat <- function(x, invals, outvals) { > x <- as.character(x) > invals <- as.character(invals) > outvals <- as.charact

[R] extracting months from a data

2016-03-09 Thread KMNanus
I have a series of dates in format 3-Oct, 10-Oct, 20-Oct, etc. I want to create a variable of just the month. If I convert the date to a character string, substr is ineffective because some of the dates have 5 characters (3-Oct) and some have 6 (10-Oct). Is there a date function that accompli

Re: [R] truncpareto() - doesn't like my data and odd error message

2016-03-09 Thread peter dalgaard
> On 09 Mar 2016, at 18:52 , John Hillier wrote: > > Dear All, > > > I am attempting to describe a distribution of height data. It appears > roughly linear on a log-log plot, so Pareto seems sensible. However, the > data are only reliable in a limited range (e.g. 2000 to 4800 m). So, I wou

Re: [R] Testing installed package of rJava in Linux

2016-03-09 Thread Stephen Connolly
The variable DISPLAY is what is causing problems. Run the command 'unset DISPLAY' before running R . Stephen On 09/03/16 01:06 PM, Uwe Ligges wrote: > I do not get this: If it works it is OK to use it. If it does not work, > you can't > > Best, > Uwe Kigges > > > > > > On 09.03.2016 17

Re: [R] Testing installed package of rJava in Linux

2016-03-09 Thread Uwe Ligges
I do not get this: If it works it is OK to use it. If it does not work, you can't Best, Uwe Kigges On 09.03.2016 17:44, Santosh wrote: Thanks for your response. Since the test failed due to X11 connectivity reasons, is it okay to use it in applications where X11 server connectivity is

[R] truncpareto() - doesn't like my data and odd error message

2016-03-09 Thread John Hillier
Dear All, I am attempting to describe a distribution of height data. It appears roughly linear on a log-log plot, so Pareto seems sensible. However, the data are only reliable in a limited range (e.g. 2000 to 4800 m). So, I would like to fit a Pareto distribution to the reliable (i.e. trunca

Re: [R] ivreg with two endogenous variables and 1 instrument respectively

2016-03-09 Thread Achim Zeileis
On Tue, 8 Mar 2016, stefania innocenti wrote: Hello, I am trying to use the ivregress function to estimate a second stage model which looks like the following: LogGDP=GEO+RULE+OPENNESS I would like to instrument Rule (RULE) with Settler mortality (SETTLER) and Openness (OPENNESS) with logFr

Re: [R] Lexical scoping for step and add1 functions

2016-03-09 Thread Jeff Newmiller
So in both my solution and your second option, lm prints that it evaluated the regression in a function context (using dfr) which the user of the function might prefer to be unaware of (they know what X.des is). Your first solution avoids that but hardcodes access to the global variable so if t

Re: [R] Testing installed package of rJava in Linux

2016-03-09 Thread Santosh
Thanks for your response. Since the test failed due to X11 connectivity reasons, is it okay to use it in applications where X11 server connectivity is not required? Thanks and much appreciated, Santosh On Tue, Mar 8, 2016 at 10:41 PM, Uwe Ligges wrote: > > > On 09.03.2016 02:19, Santosh wrote: >

Re: [R] assign a vector to list sequence

2016-03-09 Thread S Ellison
> > What I need is this: > > [[1]] > > [1] 1 2 3 > > [[1]] > > [2] 1 2 3 > > [[1]] > > [2] 1 2 3 Try rep(list(1:3), 3) S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}}

Re: [R] assign a vector to list sequence

2016-03-09 Thread Sarah Goslee
Hi, On Wed, Mar 9, 2016 at 10:22 AM, Jan Kacaba wrote: > Hello I would like to assign a vector to list sequence. I'm trying my code > bellow, but the output is not what inteded. > > # my code > mls=vector(mode="list") # my list > cseq=c(1:3) # my vector > mls[cseq]=cseq > > I get following: > [

[R] assign a vector to list sequence

2016-03-09 Thread Jan Kacaba
Hello I would like to assign a vector to list sequence. I'm trying my code bellow, but the output is not what inteded. # my code mls=vector(mode="list") # my list cseq=c(1:3) # my vector mls[cseq]=cseq I get following: [[1]] [1] 1 [[1]] [2] 2 [[1]] [2] 3 What I need is this: [[1]] [1] 1 2 3 [[1]

Re: [R] Information value

2016-03-09 Thread Michael Dewey
Just to help next time some comments in-line On 09/03/2016 14:31, Venky wrote: Hi I want to find the information value for my overall data. I have data like this.my data set name is data Best not to call your data.frame data as it may conflict with the function data() Id smoked

Re: [R] Information value

2016-03-09 Thread Sarah Goslee
A search on rseek.org for information value turns up several contributed packages that may do what you want. Sarah On Wed, Mar 9, 2016 at 9:31 AM, Venky wrote: > Hi > > I want to find the information value for my overall data. > > I have data like this.my data set name is data > > Id smoke

Re: [R] group by rows

2016-03-09 Thread Sarah Goslee
On Wed, Mar 9, 2016 at 8:28 AM, carol white wrote: > What should be FUN in aggregate as no function like mean, sum etc will be > applied I have no idea, since you haven't told us what you want the results to look like. > Carol > > > On Wednesday, March 9, 2016 1:59 PM, Sarah Goslee > wrote: >

[R] Information value

2016-03-09 Thread Venky
Hi I want to find the information value for my overall data. I have data like this.my data set name is data Id smokedrink nothing 1 yesno no 2 no yesyes 3 yesyesno . . . . Etc

Re: [R] group by rows

2016-03-09 Thread PIKAL Petr
Hi Without posting some data by dput, you hardly get any sensible answer. You can use any function which gives you appropriate result, even your own. Or even silly one like aggregate(iris[,1:3], list(iris$Species), paste, collapse="") Cheers Petr > -Original Message- > From: R-help [m

Re: [R] group by rows

2016-03-09 Thread S Ellison
> How is it possible to group rows of a matrix or a data frame by the same > values > of the first column? If you mean _group_ as in SQL GROUP BY, use aggregate() with a count or summary statistic. If you mean _sort_, just to get similar values close together, use order() For example, to sort

[R] Fw: group by rows

2016-03-09 Thread carol white via R-help
I found the right usage. Thanks On Wednesday, March 9, 2016 2:28 PM, carol white wrote: What should be FUN in aggregate as no function like mean, sum etc will be applied Carol On Wednesday, March 9, 2016 1:59 PM, Sarah Goslee wrote: Possibly aggregate(), but you posted in HT

Re: [R] group by rows

2016-03-09 Thread carol white via R-help
What should be FUN in aggregate as no function like mean, sum etc will be applied Carol On Wednesday, March 9, 2016 1:59 PM, Sarah Goslee wrote: Possibly aggregate(), but you posted in HTML so your data were mangled. Please use dput(), post in plain text, and try to explain more clear

Re: [R] group by rows

2016-03-09 Thread Sarah Goslee
Possibly aggregate(), but you posted in HTML so your data were mangled. Please use dput(), post in plain text, and try to explain more clearly what you want the result to look like. Sarah On Wed, Mar 9, 2016 at 7:09 AM, carol white via R-help wrote: > How is it possible to group rows of a matri

[R] group by rows

2016-03-09 Thread carol white via R-help
How is it possible to group rows of a matrix or a data frame by the same values of the first column? 1 14331 453452 653 3762 45 1 1433,453452 45, 653 376 Thanks Carol [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] Lexical scoping for step and add1 functions

2016-03-09 Thread S Ellison
> In a nutshell, formulas carry the environment in which they are defined along > with the variable names, and your dfr was defined in the test.FN environment, > but the formulas were defined in the global environment. I got this to work by > defining the formula character strings in the global env

Re: [R] Lexical scoping for step and add1 functions

2016-03-09 Thread Jeff Newmiller
In a nutshell, formulas carry the environment in which they are defined along with the variable names, and your dfr was defined in the test.FN environment, but the formulas were defined in the global environment. I got this to work by defining the formula character strings in the global environ

Re: [R] replace text by uniqe number

2016-03-09 Thread PIKAL Petr
Hi As you did not provide the data it is only a guess. The values are actually factors and in that case they already have unique numeric code. you can try as.numeric(yourdata) If the values are character you can transfer them to factor and use as.numeric. as.numeric(as.factor(yourdata)) Chee

[R] replace text by uniqe number

2016-03-09 Thread Ragia .
Dear group kindly if i had data frame of 2 columns that has repeated URLS ..and want to replace those urls with ID's for each one so the url will have unique ID, how  can I do this thanks in advance e.g otf  data pcworld.com open.itworld.com pcworld.com storage.itworld.com salon.com