I ran this routine but I was thinking there must be a more elegant way of doing
this.
#https://community.rstudio.com/t/how-to-average-mean-variables-in-r-based-on-the-level-of-another-variable-and-save-this-as-a-new-variable/8764/8
hcd2tmp2_summmary <- hcd2tmp2 %>%
select(.) %>%
group_by(Pr
Hi,
The conditions are not very clear. For example, it is not mentioned whether
vectors are of same length or not. Assuming the former case:
fun1 <- function(x,y){
if(length(x)==length(y) & length(x)%%2==0){
res <- x+y
}
else if(length(x)==length(y) & length(x)%%2==1){
res <- abs(x-y)
}
el
-
From: Hefri
To: r-help@r-project.org
Cc:
Sent: Thursday, November 22, 2012 6:43 AM
Subject: Re: [R] Help with loop
Hi again,
I was thinking that the interval would stop when there was a NA, ignore
subsequent NAs and only start a new interval when there was a new value. So
in the example below, the int
Hi again,
I was thinking that the interval would stop when there was a NA, ignore
subsequent NAs and only start a new interval when there was a new value. So
in the example below, the interval would stop at row 320, and a new interval
started at row 334.
> head (D, 20)
Salt time
319
Hello,
I'm glad it helped.
You should have kept this in the list, the odds of getting more answers
are bigger.
As for your problem with NAs, what do you want to do with them? Should
they count as within range?
Rui Barradas
Em 22-11-2012 10:18, Helene Frigstad escreveu:
Hi,
yes, that is a v
Hello,
If I understand it well, this might avoid a loop.
dat <- read.table(text="
Salt time
1 35.65114 2003-07-19
2 35.64226 2003-07-20
3 35.62411 2003-07-21
4 35.62473 2003-07-22
5 35.65893 2003-07-23
6 35.70140 2003-07-24
7 35.62157 2003-07-25
8 35.64122 2003-07-26
9 35.63515 2
Hello,
Try the following.
d <- read.table(text="
D Y C
a 2005 10
a 2006 0
a 2007 9
b 2005 1
b 2006 0
b 2007 1
c 2005 5
c 2006 NA
c 2007 4 ", header=TRUE)
d
prn <- lapply(split(d, d$D), function(x){
x <- x[!is.na(x$C), ]
x[c(FALSE, diff(x$C)/x$C[-length(x$C)] < -0.5 & diff(x$C) < -5), ]
Hi,
Try this:
func1<-function(x,y,z)
{ifelse(is.na(y[[x]]),z[[x]],y[[x]])}
dat3<-data.frame(lapply(colnames(df1),function(x) func1(x,df1,df2)))
colnames(dat3)<-colnames(df1)
dat3
cola colb colc cold cole
1 1.4 5.0 9.00 1.6 17.0
2 1.4 6.0 0.02 14.0 0.6
3 3.0 0.8 11.00 15.0 19.0
4
I think I just learned this myself:
Don't put the $ extension in the bracket :
df1$cola[is.na(df1$cola)]<-
>
> df2$cola
>
Instead substitute using brackets within the brackets:
df1["cola"]is.na(df1["cola"])]<-
>
> df2["cola"]
> then the "cola" s can be substituted.
>
Maybe this will help
Hello,
A one-liner could be
df1 <- read.table(text="
cola colb colc cold cole
1NA59 NA 17
2NA6 NA 14 NA
3 3NA 11 15 19
4 48 12 NA 20
", header=TRUE)
df2 <- read.table(text="
cola colb colc cold cole
1 1.4 0.8 0.02 1.6 0.6
", header=
Try this:
apply(subset.models[,-1], 1,
function(x)lm(as.formula(paste('y ~', paste(names(freeny[,-1])[x],
collapse = "+"), sep = "")), data = freeny))
On Sun, Sep 13, 2009 at 10:57 AM, Axel Urbiz wrote:
> Hi,
>
> Id like to fit one GLM model for each possible combination of inputs (i.
Hi,
On Jul 23, 2009, at 7:30 PM, Lars Bishop wrote:
Dear experts,
I'm new in R and trying to learn by writing a version of the
Perceptron
Algorithm. How can I tell in the code below to stop the iteration
when the
condition in the "for loop" is not satisfied for all training
examples?
T
Wacek Kusnierczyk wrote:
> is your data a data frame or a matrix? do you want to compute the
> differences columnwise, i.e., for each column independently? consider
> this example:
>
> # generate and display dummy data
> (d = as.data.frame(replicate(3, sample(5
>
> # compute succe
Thank you guys, it's a lot simpler than I thought.
Regards,
Rafael.
Veja quais são os assuntos do momento no Yahoo! +Buscados
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinf
On 12 Mar 2009, at 13:22, richard.cot...@hsl.gov.uk wrote:
I'm trying to write a loop to sum my data in the following way:
(the second - the first) + (the third - the second) + (the fourth -
the third) + ...
for each column.
This is just sum(diff(x)), or even x[length(x)] - x[1].
I think r
Dear Rafael,
Perhaps:
sum(diff(x))
where x is your vector. To apply above to your data set (by rows), you could
use
apply(mydata,1,function(x) sum(diff(x)))
See ?diff, ?sum and ?apply for more information.
HTH,
Jorge
On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral
wrote:
> Dear useRs,
> I'm
This is a telescoping sum that can be calculated analytically as:
(a[2] - a[1]) + ... + (a[n] - a[n-1]) = a[n] - a[1]
On Thu, Mar 12, 2009 at 9:04 AM, Rafael Moral
wrote:
> Dear useRs,
> I'm trying to write a loop to sum my data in the following way:
> (the second - the first) + (the third - t
Well actually, what about that (Assuming mydata is a data frame)
tail( mydata, 1 ) - head( mydata, 1)
since:
(the second - the first) + (the third - the second) + (the fourth - the third)
= the last - the first
Romain
Rafael Moral wrote:
Dear useRs,
I'm trying to write a loop to sum my data
> I'm trying to write a loop to sum my data in the following way:
> (the second - the first) + (the third - the second) + (the fourth -
> the third) + ...
> for each column.
This is just sum(diff(x)), or even x[length(x)] - x[1].
Regards,
Richie.
Mathematical Sciences Unit
HSL
---
Hi,
Try this;
lapply( mydata, function(x){
sum( diff( x ) )
} )
Romain
Rafael Moral wrote:
Dear useRs,
I'm trying to write a loop to sum my data in the following way:
(the second - the first) + (the third - the second) + (the fourth - the third)
+ ...
for each column.
So, I wrote someth
is your data a data frame or a matrix? do you want to compute the
differences columnwise, i.e., for each column independently? consider
this example:
# generate and display dummy data
(d = as.data.frame(replicate(3, sample(5
# compute successive differences columnwise
as.dat
Why use a loop? Try using diff()
x <- c(4, 19, 21, 45, 50, 73, 78, 83, 87, 94)
sum(diff(x))
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Rafael Moral
Sent: Thursday, March 12, 2009 9:04 AM
To: r-help@r-project.org
Subject: [R] h
22 matches
Mail list logo