Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! -Original Message- From: Chel Hee Lee [mailto:chl...@mail.usask.ca] Sent: Friday, January 23, 2015 8:09 PM To: Tan, Richard; 'r-help@R-project.org' Subject: Re: [R] get latest dates for different people in a dataset do.call(rbind, lapply(split(data, data$Name), function(x

Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! -Original Message- From: David Barron [mailto:dnbar...@gmail.com] Sent: Saturday, January 24, 2015 7:56 AM To: Tan, Richard; r-help@R-project.org Subject: Re: [R] get latest dates for different people in a dataset Hi Richard, You could also do it using the package dplyr

Re: [R] get latest dates for different people in a dataset

2015-01-26 Thread Tan, Richard
Thank you! From: William Dunlap [mailto:wdun...@tibco.com] Sent: Friday, January 23, 2015 7:14 PM To: Tan, Richard Cc: r-help@R-project.org Subject: Re: [R] get latest dates for different people in a dataset Here is one way. Sort the data.frame, first by Name then break ties with CheckInDate

[R] get latest dates for different people in a dataset

2015-01-23 Thread Tan, Richard
Hi, Can someone help for a R question? I have a data set like: NameCheckInDate Temp John 1/3/2014 97 Mary 1/3/2014 98.1 Sam 1/4/2014 97.5 John 1/4/2014 99 I'd like to return a dataset that for each Name, get the

[R] categorize a character column

2011-01-05 Thread Tan, Richard
Hi, I know I can do this with a for loop with strsplit and grep, but is there more efficient way? Given a data dataframe (input) and a category column (lst), input item loc 1 item 1.1: earnings sep item 1.2: w2 sep shelf 1 2

[R] categorize a character column

2011-01-05 Thread Tan, Richard
1.3: deductions drawer 1 C 3 item 1.1: earnings shelf 2 A Thanks, Richard From: Tan, Richard Sent: Wednesday, January 05, 2011 5:55 PM To: 'r-help@r-project.org' Subject: categorize a character column Hi, I know I can do this with a for loop with strsplit

[R] aggregate a Date column does not work?

2010-11-22 Thread Tan, Richard
Hi, I am trying to aggregate max a Date type column but have weird result, how do I fix this? a - rbind( + data.frame(name='Tom', payday=as.Date('1999-01-01')), + data.frame(name='Tom', payday=as.Date('2000-01-01')), + data.frame(name='Pete', payday=as.Date('1998-01-01')), +

Re: [R] aggregate a Date column does not work?

2010-11-22 Thread Tan, Richard
Thanks, add as.Date('1970-01-01') to the result column works. Richard -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Monday, November 22, 2010 3:51 PM To: Tan, Richard Cc: r-help@r-project.org Subject: Re: [R] aggregate a Date column does not work

Re: [R] aggregate a Date column does not work?

2010-11-22 Thread Tan, Richard
To: Tan, Richard Cc: r-help@r-project.org Subject: Re: [R] aggregate a Date column does not work? On Nov 22, 2010, at 3:54 PM, Tan, Richard wrote: Thanks, add as.Date('1970-01-01') to the result column works. But that should make them all the same date in 1970. Since aggregate renames the date

[R] aggregate text column by a few rows

2010-10-07 Thread Tan, Richard
Hi, R function aggregate can only take summary stats functions, can I aggregate text columns? For example, for the dataframe below, a - rbind(data.frame(id=1, name='Tom', hobby='fishing'),data.frame(id=1, name='Tom', hobby='reading'),data.frame(id=2, name='Mary',

Re: [R] aggregate text column by a few rows

2010-10-07 Thread Tan, Richard
Thank you! Richard -Original Message- From: jim holtman [mailto:jholt...@gmail.com] Sent: Thursday, October 07, 2010 12:08 PM To: Tan, Richard Cc: r-help@r-project.org Subject: Re: [R] aggregate text column by a few rows try this using sqldf: a id name hobby 1 1 Tom fishing 2

[R] get top n rows group by a column from a dataframe

2010-09-16 Thread Tan, Richard
Hi, is there an R function like sql's TOP key word? I have a dataframe that has 3 columns: company, person, salary How do I get top 5 highest paid person for each company, and if I have fewer than 5 people for a company, just return all of them? Thanks, Richard

Re: [R] get top n rows group by a column from a dataframe

2010-09-16 Thread Tan, Richard
Hi Richard Thanks for the suggestion, but I want top 5 salary for each company, not the whole list. I don't see how your way can work? Thanks, Richard From: RICHARD M. HEIBERGER [mailto:r...@temple.edu] Sent: Thursday, September 16, 2010 11:53 AM To: Tan, Richard Cc: r-help@r

Re: [R] get top n rows group by a column from a dataframe

2010-09-16 Thread Tan, Richard
Thanks, it works. Richard From: Henrique Dallazuanna [mailto:www...@gmail.com] Sent: Thursday, September 16, 2010 1:56 PM To: Tan, Richard Cc: RICHARD M. HEIBERGER; r-help@r-project.org Subject: Re: [R] get top n rows group by a column from a dataframe You can try this: (Using

[R] data frame select max group by like function

2010-03-09 Thread Tan, Richard
Hi, I have a data frame with 3 columns: ID, year and score. How can I select for each unique ID, the year that has the max score? For example, for data frame ID, year, score tom, 1995, 88 rick, 1994, 90 mary, 2000, 97 tom, 1998, 60 mary, 1998,100 I shall have ID, year, score tom, 1995, 88

Re: [R] data frame select max group by like function

2010-03-09 Thread Tan, Richard
Thanks all for the help! -Original Message- From: William Dunlap [mailto:wdun...@tibco.com] Sent: Tuesday, March 09, 2010 5:58 PM To: Phil Spector; Tan, Richard Cc: r-help@r-project.org Subject: RE: [R] data frame select max group by like function And yet another way is isLastInRun

[R] gsub does not support \b?

2009-11-10 Thread Tan, Richard
Hello, can someone help? How come gsub(\bINDS\b,INDUSTRIES,ADVANCED ENERGY INDS) [1] ADVANCED ENERGY INDS not ADVANCED ENERGY INDUSTRIES Thanks. Richard [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] gsub does not support \b?

2009-11-10 Thread Tan, Richard
Ok, I figured it out. My stupid mistake, should be \\b instead of \b. From: Tan, Richard Sent: Tuesday, November 10, 2009 3:36 PM To: 'r-help@r-project.org' Subject: gsub does not support \b? Hello, can someone help? How come gsub(\bINDS\b,INDUSTRIES

Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-09 Thread Tan, Richard
] Sent: Tuesday, June 09, 2009 1:06 PM To: Greg Snow Cc: Marc Schwartz; Barry Rowlingson; r-help@r-project.org; Tan, Richard Subject: Re: [R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number Greg Snow wrote: Here is one way using a single

[R] Regex question to find a string that contains 5-9 alpha-numeric characters, at least one of which is a number

2009-06-08 Thread Tan, Richard
Hi, This is not exactly an R question but I am trying to use gsub to replace a string that contains 5-9 alpha-numeric characters, at least one of which is a number. Is there a good way to write it in a one line regex? Thanks, Richard __

[R] toupper does not work in sub + regex

2009-04-13 Thread Tan, Richard
Hi, I don't know what I am doing wrong to the toupper does not seem working in sub + regex. The following returns 's' not the upper class 'S' as I expect: sub(q_([a-z])[a-zA-Z]*,toupper('\\1'),q_sviRaw) Can someone tell me where I did wrong? Thanks, Richard [[alternative HTML

Re: [R] toupper does not work in sub + regex

2009-04-13 Thread Tan, Richard
Thanks, Martin. I did not realize that. I never used perl compatible regex before but seems now I should! Richard -Original Message- From: Martin Morgan [mailto:mtmor...@fhcrc.org] Sent: Monday, April 13, 2009 12:08 PM To: Tan, Richard Subject: Re: [R] toupper does not work in sub

Re: [R] toupper does not work in sub + regex

2009-04-13 Thread Tan, Richard
] Sent: Monday, April 13, 2009 1:17 PM To: Tan, Richard; r-help@r-project.org Subject: Re: [R] toupper does not work in sub + regex You could also use \\U and \\L in the replacement with perl=TRUE. \\U converts the rest of the replacement to upper case and \\L converts to lowercase. (By replacement

[R] search for string insider a string

2009-03-13 Thread Tan, Richard
Hi, sorry if it is a too stupid question, but how do I a string search in R: I have a dataframe A with A$test like: test1 bcdtestblabla2.1bla cdtestblablabla3.88blabla and I want to search for string that start with 'dtest' and ends with number and return the location of that substring and

Re: [R] search for string insider a string

2009-03-13 Thread Tan, Richard
That works. I want the position just for the purpose of my later manual check. Thanks a lot Gabor. -Original Message- From: Gabor Grothendieck [mailto:ggrothendi...@gmail.com] Sent: Friday, March 13, 2009 2:18 PM To: Tan, Richard Cc: r-help@r-project.org Subject: Re: [R] search

[R] Get top cluster for each item in a correlation matrix

2009-02-23 Thread Tan, Richard
Hi, I posted a question a few days ago and got extremely well response. https://stat.ethz.ch/pipermail/r-help/2009-February/188225.html. Now I have a somewhat related question: I have a correlation matrix of about 3000 items, with 1 on diagonal ( for example, cor.mat -

Re: [R] transform key value pair to column

2009-02-19 Thread Tan, Richard
Thank you, works! -Original Message- From: Rowe, Brian Lee Yung (Portfolio Analytics) [mailto:b_r...@ml.com] Sent: Thursday, February 19, 2009 5:52 PM To: Wacek Kusnierczyk; Tan, Richard Cc: r-help@r-project.org Subject: RE: [R] transform key value pair to column Try this: dummy id

[R] get top 50 correlated item from a correlation matrix for each item

2009-02-12 Thread Tan, Richard
Hi, I have a correlation matrix of about 3000 items, i.e., a 3000*3000 matrix. For each of the 3000 items, I want to get the top 50 items that have the highest correlation with it (excluding itself) and generate a data frame with 3 columns like (ID, ID2, cor), where ID is those 3000 items each

Re: [R] get top 50 correlated item from a correlation matrix for each item

2009-02-12 Thread Tan, Richard
Works like a charm, thank you! -Original Message- From: Dimitris Rizopoulos [mailto:d.rizopou...@erasmusmc.nl] Sent: Thursday, February 12, 2009 12:11 PM To: Tan, Richard Cc: r-help@r-project.org Subject: Re: [R] get top 50 correlated item from a correlation matrix for each item