Displaying 20 results from an estimated 10000 matches similar to: "execute array of functions"
2009 Dec 30
2
select elements and transpose
Hi all,
Given the following,
> xx
[[1]]
V1 V2 V3
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[[2]]
V1 V2 V3
[1,]10 11 12
[2,]13 14 15
[3,]16 17 18
[[3]]
V1 V2 V3
[1,]19 20 21
[2,]22 23 24
[3,]25 26 27
how do i extract elements in each file so that after transpose, it looks
something like the following;
1
10
19
2
11
20
3
12
21
and so on..
Thanks..
--
Muhammad
2009 Dec 27
3
Scaling error
Hi useRs,
I ran into an inconsistent output problem again. Here is the simplify
illustration
I've got a matrix as follows
> x
V1 V2 V3
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
Associated with the matrix is a scaling factor, sca, derived from, say
the mean of the respective columns, V1-V3;
> sca
V1 V2 V3
2.5 1.7 3.6
2009 Dec 04
2
Standard deviation for each element in a set of matrices
Hello R-users,
I would like to know how to find the standard deviation for each element
in a set of matrices.
Given the following files,
File1 File2 File3
1 1 1 4 4 4 7 7 7
2 2 2 5 5 5 8 8 8
3 3 3 6 6 6 9 9 9
I want to calculate the standard deviation for every cell in the file
(I'm using gridded data). The desired output is
Output
3 3 3
3 3
2011 Jun 18
3
Array
Hi,
Can someone advise why the followind did not produce the array, given
the condition specified?
s <- 1
a1 <- array(dim=c(1,4))
a2 <- array(dim=c(2,4))
arr <- ifelse(s==0,a1,a2)
Thanks.
Muhammad
2010 Jan 02
1
Question on Reduce + rollmean
Hello useRs,
I'd like to perform a moving average on the dataset, xx. I've tried
combining the functions Reduce and rollmean but it didn't work.
> r <- function(n) rollmean(n, 2) # where 2 = averaging interval
> output < - Reduce("r", x)
Error in f(init, x[[i]]) : unused argument(s) (x[[i]])
Is there anything wrong with the code in the first place?
where
2010 Jan 16
2
Drought severity index: Excel to R
Dear all,
I'm trying to make an R code for the drought severity index (DSI)
developed by Philips and McGregor (1998). You can refer to the
description of the algorithm on page 19 from
http://dissertations.port.ac.uk/229/01/MaloneS.pdf
The code is given in Excel as the following and can be found on page 60
from the same link.
C7 =
IF(C6<0,IF(@SUM(A6:A1)<0,C6+A6,"0"),
2010 Jan 29
2
Create matrix with subset from unlist
Hello all,
I'm trying to create a 2x2 matrix, 32 times after unlist() so that I can
convert the list to matrix. I've looked through the R archive but
couldn't find the answer. There is what I've done.
> f <- system("ls *.txt", intern=TRUE)
> x <- lapply(f, read.table)
> x
[[1]]
V1 V2
1 -27.3 14.4
2 29.0 -38.1
[[2]]
V1 V2
1 14.4
2010 Jan 06
1
Increment in loop
useRs,
I'm getting limited success in trying to apply increment in a loop.
The following defined function creates a +1 increment
incr <- function(x){
eval.parent(substitute(x <- x + 1))
print(x) }
How do I apply it in a loop on my test dataset, x1, so that the procedure becomes
x1[c(1:2)]
x1[c(2:3)]
x1[c(3:4)]
where x1 =
> m <- matrix(1:3,3,3)
> x1 <- list(m, m+1,
2011 Sep 24
2
ncdf - install error
Dear all,
I'm having issues with the installation of the ncdf package. It returns a
non-zero exit status. Can anyone suggest what I should do next? FYI, I do
not have problems installing other packages.
Thanks.
Muhammad
* installing *source* package ?ncdf? ...
checking for nc-config... /usr/local/bin/nc-config
configure: creating ./config.status
config.status: creating src/Makevars
**
2009 Dec 07
1
Output multiple files
Hello,
I want the ouput to take the name of the original file. I have the following code - but the problem is that the output overrides the original file which I desire not.
So given an input file called File1.txt, I want the ouput to be called File1.out.txt, or something along this line. I'm working with many files, fyi.
out=c("file1.txt", "file2.txt",
2010 Apr 22
3
using which to select range of values
Hi all,
I would like to get the array index for a range of values, say 0 < x <
1.5. I'm wondering if there is an alternative for the following which
I've done
x0 <- rnorm(100)
x1 <- ifelse(x0 > 0 & x0 < 1.5,"t","f")
x2 <- which(x1=="t",arr.ind=TRUE)
x0[x2]
Thanks.
--
Muhammad
2009 Dec 20
3
Object of type 'closure' not subsettable
Hi all,
How can I overcome the error "object of type 'closure' not subsettable"
I ran the following script
seq <- paste(seq(1914, 1916, by=1), "*.y", sep=".") # make sequence
c <- 3 # total number of files
d2 <- file # creates dummy file
# Input sequence in loop
for (i in 1:3){
list <- list.files("~/ukcp09/txt/x.djf", seq[[i]])
file
2011 Jan 03
3
optimize
Hi all,
I'm trying to get the value of y when x=203 by using the intersect of
three curves. The horizontal curve does not meet with the
other two. How can I rectify the code below?
Thanks
Muhammad
ts <- 1:10
dd <- 10:1
ts <- seq(200,209,1)
dd <- c(NA,NA,NA,NA,1.87,1.83,1.86,NA,1.95,1.96)
plot(ts,dd,ylim=c(1.5,2))
abline(lm(dd~ts),col="blue",lty=2)
2010 May 06
2
reading in file with different row length
Hi all,
I have a file, say, test.txt, which contains the following information.
I'm trying to read in the file and specifying the missing values as NA
so that each column has the same number of rows.
I've tried all sorts of manipulation but to no avail.
r1 r2 r3
1 3
2 3
3 2 3
4 2 3
5 2 3
6 2 3
7 2
8 2
9 2 3
The output should be
r1 r2 r3
1 NA 3
2 NA 3
3 2 3
4 2 3
5 2 3
6 2 3
7 2
2011 Oct 31
1
Significance of trend
Hi everyone,
I'm trying to determine the significance of a trendline. From my internet
search months ago, I came across the following post. I modified tim and
dat for simiplicity.
tim <- 1:10
dat <- c(0.17, 1.09 ,0.11, 0.82, 0.23, 0.38 ,2.47 ,0.41 ,0.75, 1.44)
fstat <- summary(lm(dat~tim))$fstatistic
p.val <-
2010 Jun 25
1
Finding sets
Hi all,
I'd like to find how many sets of 1s there are in the following example;
x <- rep(c(1,2,1,3,5), each=5)
I know that there are two sets of 1s, visually. Any function in R that
allows me to automate the process?
Thanks.
Muhammad
2010 Oct 19
2
nls & optimize
Hi all,
I'm plotting to get the intersection value of three curves. Defining
the x-axis as dsm, the following code works;
dsm = c(800,600,NA,525,NA,450,400,NA,NA,NA,0)
s3 = seq(0.05,1.05,0.1)
plot(dsm,s3,col="blue",las=1,ylab="fraction",xlab="distance (km)")
fc <- function(x,a,b){a*exp(-b*x)}
fm <- nls(s3~fc(dsm,a,b),start=c(a=1,b=0))
co <- coef(fm)
2009 Dec 02
2
Arithmetic on multiple files
Dear R-users,
I'd like to perform arithmetic functions on 1000 files containing a
2000x2000 matrix. Can anyone advise?
For example,
File1 File2 Output
1 1 1 4 4 4 5 5 5
2 2 2 + 5 5 5 = 7 7 7
3 3 3 6 6 6 9 9 9
Muhammad
--
Muhammad Rahiz | Doctoral Student in Regional Climate Modeling
Climate Research
2010 Jan 12
1
Drought Severity Index (DSI)
Does anyone have the code to calculate the drought severity index?
--
Muhammad Rahiz | Doctoral Student in Regional Climate Modeling
Climate Research Laboratory, School of Geography & the Environment
Oxford University Centre for the Environment, University of Oxford
South Parks Road, Oxford, OX1 3QY, United Kingdom
Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: muhammad.rahiz
2009 Dec 26
1
if else does not return right value
Hi all,
I'm not getting the right results for values that are >99 using the if
else function. The following illustrates the problem
> x <- as.matrix(read.table("test.txt"))
> x
V1 V2 V3
[1,] 47 1 43
[2,] 83 2 42
[3,] 1 3 41
[4,] 39 4 40
[5,] 23 5 39
[6,] 23 6 38
[7,] 39 7 37
[8,] 32 8 36
[9,] 73 9 35
[10,] 124 10 34
Specifying the