Your use of HTML email corrupted your example slightly, but I was able to
fix it. Please follow the Posting Guide and set your emails to Plain Text
mode when posting to this mailing list in the future.
Here is one way:
# you have to be careful about mucking with factors
# convert columns to fa
Marine:
Thanks for the reproducible example. I would not have fooled with this
otherwise!
1. First note that your specification that you wish to replace only
those values in col3 and col4 of df1 that don't match with those of
df2 is irrelevant: if you replace those that do match you don't change
If you don't need all that FUN flexibility, you can get this done way
faster with the aperm and colMeans functions:
tst <- matrix( seq.int( 1440 * 360 )
, ncol = 1440
, nrow = 360
)
tst.small <- matrix( seq.int( 8 * 4 )
, ncol = 8
Hello,
I have two data frames with different sizes but with the same number of columns.
> df1 <- data.frame(col1 = c(1:6), col2 = c(rep("a", 3), rep("b", 3)), col3 =
> c(rep("AA", 2), rep("BB", 2), rep("CC", 2)), col4=c(1,8,6,9,7,6))
> df1
col1 col2 col3 col4
11a AA1
22
Thank you so much Jim.
Here is the code.
sum_balok <- as.vector(by(dt1$x,dt1$year,sum,na.rm=TRUE))
sum_gambang <- as.vector(by(dt2$x,dt2$year,sum,na.rm=TRUE))
sum_sgsoi <- as.vector(by(dt3$x,dt3$year,sum,na.rm=TRUE))
sum_jpsphg <- as.vector(by(dt4$x,dt4$year,sum,na.rm=TRUE))
sum_pbesar <- a
Dear r-users,
I would like to use lapply for the following task:
## Kolmogorov-Smirnov
ks.test(stn_all[,1][stn_all[,1] > 0],stn_all_gen[,1][stn_all_gen[,1] > 0])
ks.test(stn_all[,2][stn_all[,2] > 0],stn_all_gen[,2][stn_all_gen[,2] > 0])
ks.test(stn_all[,3][stn_all[,3] > 0],stn_all_gen[,3][stn_all
For the record, the array.apply code can be fixed as below, but then it is
slower than the expand.grid version.
aggregate.nx.ny.array.apply <- function(dta,nx=2,ny=2, FUN=mean,...)
{
a <- array(dta, dim = c(ny, nrow( dta ) %/% ny, nx, ncol( dta ) %/% nx))
apply( a, c(2, 4), FUN, ... )
}
--
Below.
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Sat, Jul 30, 2016 at 11:38 AM, Neal H. Walfield wrote:
> On Sat, 30 Jul 2016 20:35:40 +0200,
> Jeff Newm
> peter dalgaard
> on Tue, 26 Jul 2016 23:30:31 +0200 writes:
>> On 26 Jul 2016, at 22:26 , Hadley Wickham
>> wrote:
>>
>> On Tue, Jul 26, 2016 at 3:24 AM, Martin Maechler
>> wrote:
>>>
> ...
>> To me, this would be the most sensible default behavio
On Sat, 30 Jul 2016 20:35:40 +0200,
Jeff Newmiller wrote:
>
> >> [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F)
> >
> >I'm not sure what you mean by NOT here. You get the same answer as I
> >do, as far as I can see.
> >
>
> # valid R
> T <- FALSE
> # invalid R
> TRUE <- FALSE
>
> It is much muc
>> [1] TRUE FALSE TRUE FALSE ## NOT c(T,F,T,F)
>
>I'm not sure what you mean by NOT here. You get the same answer as I
>do, as far as I can see.
>
# valid R
T <- FALSE
# invalid R
TRUE <- FALSE
It is much much safer and clearer to use TRUE/FALSE than T/F. So
c( TRUE, FALSE, TRUE, FALSE ) ma
Hi all,
thanks for the suggestions, I did some timing tests, see below.
Unfortunately the aggregate.nx.ny.array.apply, does not produce the expected
result.
So the fastest seems to be the aggregate.nx.ny.expand.grid, though the double
for loop is not that much slower.
many thanks
Peter
> tst=m
Hello,
I don't have a solution but see the difference between the two loops below.
for(j in 1:2)
for(i in 1:2){
cat(y[i,j], "\n")
cat(x[i,j][[1]], "\n")
cat(y[i,j] %in% x[i,j], "\n", "\n")
}
for(j in 1:2)
for(i in 1:2){
cat(y[i,j], "\n")
cat(x[
On Sat, 30 Jul 2016 19:28:42 +0200,
Bert Gunter wrote:
> Bottom line: No, I dont see any vectorized way to do this.
>
> However, the following may offer some slight improvement over your approach.
>
> 1. Why do you need to store these as arrays, which are merely vectors
> with a "dim" attribute?
Bottom line: No, I dont see any vectorized way to do this.
However, the following may offer some slight improvement over your approach.
1. Why do you need to store these as arrays, which are merely vectors
with a "dim" attribute?
## convert to vectors (a list is also a vector):
dim(x) <- NULL;
I have a matrix of lists. Something along the lists of (but much
bigger than):
x = array(dim=c(2, 2), data=list())
x[1,1] = list(1:5)
x[2,1] = list(6:9)
x[1,2] = list(10:13)
x[2,2] = list(14:16)
Each list contains a number of observations/ground truth for a
particular state. That is,
Hi Courtney,
I haven't seen any answers to your question, and perhaps it is because
others, like I, were unable to open the file you attached. The
uninformative labels you are getting may be the names of values or the
character value of factors. Is there a sample data set from the
original file tha
17 matches
Mail list logo