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 same value (in your exam

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 to me, so I'm not sure t

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

[R] data frame question

2017-08-06 Thread Andras Farkas via R-help
Dear All, wonder if you have thoughts on the following: let us say we have: df<-data.frame(a=c(1,2,3,4,5,1,2,3,4,5,6,7,8),b=c(0,1,2,3,4,0,1,2,3,4,5,6,7)) I would like to rewrite values in column name "a" based on values in column name "b", where based on a certain value of column "b" the ne

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[b 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 <

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

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 con

[R] data frame question

2013-12-09 Thread Andras Farkas
Dear All please help with the following: I have: a <-seq(0,10,by=1) b <-c(10:20) d <-cbind(a,b) f <-16 I would like to select the value in column a based on a value in column b, where the value in column b is the 1st value that is smaller then f. Thus I should end up with the number 5 because

Re: [R] Data frame question

2013-04-01 Thread arun
oss To: r-help@r-project.org Cc: Sent: Monday, April 1, 2013 11:54 AM Subject: [R] Data frame question Hello, I have 2 data frames:  activity and dates.  Activity contains a l variable listing all activities:  activityA, activityB etc. The dates contain all the valid business dates.  I

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 wrote: > Hello, > > I have 2 data frames: activity and dates. Activity contains a l variable > list

[R] Data frame question

2013-04-01 Thread ramoss
Hello, I have 2 data frames: activity and dates. Activity contains a l variable listing all activities: activityA, activityB etc. The dates contain all the valid business dates. I need to combine the 2 so that I get a single data frame activitydat that contains the activity name along w/ evevr

Re: [R] Data frame question

2010-03-12 Thread Claudia Beleites
rate Research Laboratory - E-mail: apjawor...@mmm.com Tel: (651) 733-6092 Fax: (651) 736-3122 From: Claudia Beleites 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 tro

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:

[R] Data frame question

2010-03-12 Thread apjaworski
Hi, I have the following question about creating data frames. I want to create a data frame with 2 components: a vector and a matrix. Let me use a simple example: y <- rnorm(10) x <- matrix(rnorm(150), nrow=10) Now if I do dd <- data.frame(x=x, y=y) I get a data frame with 16 colums, but if

[R] data frame question

2008-09-03 Thread Nair, Murlidharan T
I have a data frame containing sequences and I am interested in changing a few sequences in a window and the swapping the original sequence back after I have completed my analysis. My temporary data frame that I am creating seq.in.window does not like the way I am making me assignment. The vari

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 questi

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[ x>3 ]<-NA; df$col1<-x; rm(x) -Kimmo __

Re: [R] data frame question

2008-02-14 Thread joseph
t;; r-help@r-project.org 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: > > >

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. > > >

Re: [R] data frame question

2008-02-14 Thread Stefan Grosse
On Thursday 14 February 2008 06:27:07 pm Stefan Grosse wrote: SG> df$col3<-df1$col1*2 ups it should be df1$col3<-df1$col1*2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-

Re: [R] data frame question

2008-02-14 Thread Stefan Grosse
On Thursday 14 February 2008 06:12:23 pm joseph wrote: jo> I have a data frame df1 in which I would like to multiply col1 jo> by 2. jo> The way I did it does not allow me to keep the old data jo> frame. jo> jo> jo> How can I do this and be able to create a new data frame jo> df2? jo> jo> jo> > df1$

Re: [R] data frame question

2008-02-14 Thread Henrique Dallazuanna
If I understand: df2 <- transform(df1, col3=col1*2) On 14/02/2008, 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 and be able

Re: [R] data frame question

2008-02-14 Thread Gabor Csardi
df2 = df ? G. On Thu, Feb 14, 2008 at 09:12:23AM -0800, joseph 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 and be able to create a new data frame

[R] data frame question

2008-02-14 Thread joseph
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 and be able to create a new data frame df2? > df1= data.frame(col1= c(3, 5, NA, 1), col2= c(4, NA,6, 2)) > df1 col1 col2 13

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 w

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 wit

[R] data frame question

2008-02-10 Thread joseph
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 column containing the average score (average_score) from