Re: [R] data frame question

2017-08-06 Thread Andras Farkas via R-help
thank you both... assumption is in fact that a and b are always the same length... these work for me well... much appreciate it... Andras On Sunday, August 6, 2017 12:14 PM, Ulrik Stervbo wrote: Hi Andreas, assuming that the increment is always indicated by the

Re: [R] data frame question

2017-08-06 Thread Ulrik Stervbo
Hi Andreas, assuming that the increment is always indicated by the same value (in your example 0), this could work: df$a <- cumsum(seq_along(df$b) %in% which(df$b == 0)) df HTH, Ulrik On Sun, 6 Aug 2017 at 18:06 Bert Gunter wrote: > Your specification is a bit unclear

Re: [R] data frame question

2017-08-06 Thread Bert Gunter
Your specification is a bit unclear to me, so I'm not sure the below is really what you want. For example, your example seems to imply that a and b must be of the same length, but I do not see that your description requires this. So the following may not be what you want exactly, but one way to do

Re: [R] data frame question

2013-12-09 Thread Sarah Goslee
Thank you for providing a reproducible example. I tweaked it a little bit to make it actually a data frame problem. There are lots of ways to do this; here's one approach. On second thought, this looks a lot like homework, so perhaps instead I'll just suggest using subset() with more than one

Re: [R] data frame question

2013-12-09 Thread Sarah Goslee
If it's not homework, then I'm happy to provide more help: a -seq(0,10,by=1) b -c(10:20) d -data.frame(a=a,b=b) f -16 subset(d, b f b == max(b[b f]))$a # I'd turn it into a function getVal - function(d, f) { subset(d, b f b == max(b[b f]))$a } Sarah On Mon, Dec 9, 2013 at 3:50

Re: [R] data frame question

2013-12-09 Thread Toth, Denes
Hi Andras, here is an other solution which also works if b contains missing values: a -seq(0,10,by=1) b -c(NA, 11:20) f -16 # a[which.max(b[bf])] # However, your question seems a bit artificial. Maybe you converted your original question to a suboptimal problem. HTH, Denes If it's not

Re: [R] Data frame question

2013-04-01 Thread Sarah Goslee
That sounds like a job for merge(). If you provide an actual reproducible example using dput(), then you will likely get some actual runnable code. Sarah On Mon, Apr 1, 2013 at 11:54 AM, ramoss ramine.mossad...@finra.org wrote: Hello, I have 2 data frames: activity and dates. Activity

Re: [R] Data frame question

2013-04-01 Thread arun
Hi, Not sure if this is what you wanted: activity- data.frame(Name=paste0(activity,LETTERS[1:5]),stringsAsFactors=FALSE) dates1- data.frame(dat=as.Date(c(2013-02-01,2013-02-04,2013-02-05),format=%Y-%m-%d)) merge(dates1,activity) #  dat  Name #1  2013-02-01 activityA #2  2013-02-04

Re: [R] Data frame question

2010-03-12 Thread Claudia Beleites
Andy, Did you run into any kind of trouble? I'm asking because I'm maintaining a package for spectroscopic data that heavily uses I (spectra.matrix) ... However, once you have the matrix safe inside the data.frame, you can delete the AsIs: a - matrix (1:9, 3) str (a) int [1:3, 1:3] 1 2

Re: [R] Data frame question

2010-03-12 Thread Claudia Beleites
-mail: apjawor...@mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 From: Claudia Beleites cbelei...@units.it To: apjawor...@mmm.com Cc: r-help@r-project.org Date: 03/12/2010 02:13 PM Subject:Re: [R] Data frame question Andy, Did you run into any kind of trouble? I'm

Re: [R] data frame question

2008-02-14 Thread John Kane
Create the new data.frame and do the muliplying on it? df2 - df1 df2[,1] - df2[,1]*2 --- joseph [EMAIL PROTECTED] wrote: Hi I have a data frame df1 in which I would like to multiply col1 by 2. The way I did it does not allow me to keep the old data frame. How can I do this

Re: [R] data frame question

2008-02-14 Thread joseph
Cc: r-help@r-project.org Sent: Thursday, February 14, 2008 3:09:40 PM Subject: Re: [R] data frame question Create the new data.frame and do the muliplying on it? df2 - df1 df2[,1] - df2[,1]*2 --- joseph [EMAIL PROTECTED] wrote: Hi I have a data frame df1

Re: [R] data frame question

2008-02-14 Thread K. Elo
Hi, joseph wrote (15.2.2008): Thanks. I have another question: In the following data frame df, I want to replace all values in col1 that are higher than 3 with NA. df= data.frame(col1=c(1:5, NA),col2= c(2,NA,4:7)) My suggestion: x-df$col1; x[ x3 ]-NA; df$col1-x; rm(x) -Kimmo

Re: [R] data frame question

2008-02-14 Thread Bill.Venables
... or in one step df - transform(df, col1 = ifelse(col1 3, NA, col1)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of K. Elo Sent: Friday, 15 February 2008 4:29 PM To: r-help@r-project.org Subject: Re: [R] data frame question Hi

Re: [R] data frame question

2008-02-10 Thread Mark Wardle
On 10/02/2008, joseph [EMAIL PROTECTED] wrote: Hello I have 2 data frames df1 and df2. I would like to create a new data frame new_df which will contain only the common rows based on the first 2 columns (chrN and start). The column score in the new data frame should be replaced with a

Re: [R] data frame question

2008-02-10 Thread David Winsemius
joseph [EMAIL PROTECTED] wrote in news:[EMAIL PROTECTED]: I have 2 data frames df1 and df2. I would like to create a new data frame new_df which will contain only the common rows based on the first 2 columns (chrN and start). The column score in the new data frame should be replaced with a