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
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
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
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
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
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
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
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
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/
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
: 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 need to combine the 2 so
that I get a single data
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,
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
-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
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
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
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
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
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
... 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
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
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
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
23 matches
Mail list logo