Re: [R] how to extract from list

2012-10-16 Thread Muhammad Rahiz
-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Muhammad Rahiz (za) +27 071 719 0104 (skype) muhammad.rahiz [[alternative HTML version deleted]]

Re: [R] Correlating zero-truncated data

2012-03-07 Thread Muhammad Rahiz
thanks petr. -- Muhammad On Wed, 7 Mar 2012, Petr Savicky wrote: On Wed, Mar 07, 2012 at 09:42:15AM +, Muhammad Rahiz wrote: Dear all, Does anyone know of a function in R which allows for correlation of zero-truncated timeseries such as x and y as illustrated below? x <- rnorm(100

[R] Correlating zero-truncated data

2012-03-07 Thread Muhammad Rahiz
Dear all, Does anyone know of a function in R which allows for correlation of zero-truncated timeseries such as x and y as illustrated below? x <- rnorm(100) x[which(x<0)] <- 0 y <- abs(rnorm(100)) Thanks -- Muhammad __ R-help@r-project.org maili

[R] execute array of functions

2012-02-14 Thread Muhammad Rahiz
Hi all, I'm trying to get the min and max of a sequence of number using a loop like the folllowing. Can anyone point me to why it doesn't work. Thanks. type<- c("min","max") n <- 1:10 for (a in 1:2){ print(type[a](n)) } -- Muhammad

Re: [R] Title for a group of plots?

2011-11-10 Thread Muhammad Rahiz
Perhaps something like this? par(oma=c(0,0,2,0)) par(mar=c(1,1,1,1)) par(mfcol=c(3,1)) plot(rnorm(10)) mtext("title") plot(rnorm(10)) plot(rnorm(10)) -- Muhammad Rahiz On Thu, 10 Nov 2011, Kevin Burton wrote: I can get multiple plots on a page like: op <- par(mfcol = c(3,

Re: [R] Significance of trend

2011-11-01 Thread Muhammad Rahiz
t 31, 2011 at 2:51 PM, Muhammad Rahiz wrote: 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

[R] Significance of trend

2011-10-31 Thread Muhammad Rahiz
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))$fsta

[R] ncdf - install error

2011-09-23 Thread Muhammad Rahiz
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... /us

Re: [R] Array

2011-06-18 Thread Muhammad Rahiz
Understood now. Thanks Duncan. Muhammad On Sat, 18 Jun 2011, Duncan Murdoch wrote: On 11-06-18 10:45 AM, Muhammad Rahiz wrote: 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

[R] Array

2011-06-18 Thread Muhammad Rahiz
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 __ R-help@r-project.org mailing list https://stat.

[R] Polygon question

2011-06-16 Thread Muhammad Rahiz
Hi all, I have the following script which fills the values which are less than the mean of a given timeseries. If you look closely, the colored regions are "out of line". Any suggestions how I can rectify this? Thanks Muhammad # - #rm(list=ls()) x <- abs(rnorm(100)) tt <- 1:100 m <- m

Re: [R] modify a data frame by values in the columns

2011-06-03 Thread Muhammad Rahiz
Hi Jason, This is one way; c1 <- seq(2,20,2) c2 <- seq(1,19,2) c3 <- cbind(c1,c2) c3[,1][which(c3[,1]<12)] <- -1 c3[,2][which(c3[,2]>10)] <- -1 Muhammad On Fri, 3 Jun 2011, Jason024 wrote: I have a data frame like this: col1 col2 r1 21 r2 43 r3 65 r4 87 r

[R] Fit data to distribution

2011-06-03 Thread Muhammad Rahiz
ensity(x)) lines(density(y),col="red") legend("topright",legend=c("x","y"),col=c("black","red"),lty=1,bty="n") x1 <- fitdistr(x,"gamma")$estimate # get scale and rate -- Muhammad Rahiz __

Re: [R] Quick recode of -999 to NA in R

2011-03-30 Thread Muhammad Rahiz
Try using a loop like the following dat0 <- read.table("time1.dat") id <- c("e1dq", "e1arcp", "e1dev", "s1prcp", "s1nrcp","s1ints","a1gpar", "a1pias", "a1devt") for (a in 1:length

Re: [R] plotting multiple figures on one page

2011-03-17 Thread Muhammad Rahiz
Scarlet, If the mfrow is being overridden, perhaps the rimage package might be able to piece the individual plots... -- Muhammad Rahiz Researcher & DPhil Candidate (Climate Systems & Policy) School of Geography & the Environment University of Oxford On Thu, 17 Mar 2011, scarlet

Re: [R] optimize

2011-01-03 Thread Muhammad Rahiz
Josh's recommendation to use predict works. At the same time, I'll work on your suggestions, David. Thanks. Muhammad Rahiz Researcher & DPhil Candidate (Climate Systems & Policy) School of Geography & the Environment University of Oxford On Mon, 3 Jan 2011, David Winsem

[R] optimize

2011-01-03 Thread Muhammad Rahiz
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.9

Re: [R] nls & optimize

2010-10-20 Thread Muhammad Rahiz
That works - Thanks Ravi. Muhammad Rahiz On Tue, 19 Oct 2010, Ravi Varadhan wrote: You can do this. dsm = c(800,600,NA,525,NA,450,400,NA,NA,NA,0) s3 = seq(0.05,1.05,0.1) plot(s3,dsm,col="blue",las=1,xlab="fraction",ylab="distance (km)") fc <- function(x,a

[R] nls & optimize

2010-10-19 Thread Muhammad Rahiz
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)

[R] Error in which()

2010-07-08 Thread Muhammad Rahiz
Hi all, I'm trying to filter data into respective numbers. For example, if the data ranges from 0 to <0.1, group the data. And so on for the rest of the data. There are inconsistencies in the output. For example, b1[[3]] lumps all the 0.2s and 0.3s together while 0.6s are not in the output.

[R] Finding sets

2010-06-25 Thread Muhammad Rahiz
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 __ R-help@

Re: [R] long command line cut in 2 parts

2010-05-13 Thread Muhammad Rahiz
Dear Arnaud, Wrap a pair of curly brackets around the command line and remove the "+" like the following; zz<-{merge(transform(merge(value,allcon,all.y=T),SHORTDESCRIPTION=NULL, VALUE=NULL,PL=-VALUE*pl,quantity=NULL),PosB,all.x=T,sort=F )} Muhammad arnaud Gaboury wrote: Dear group, I have

Re: [R] reading in file with different row length

2010-05-06 Thread Muhammad Rahiz
o spaces replaced by two commas, ... Then read.csv should handle it fine. On Thu, May 6, 2010 at 12:10 PM, Muhammad Rahiz mailto:muhammad.ra...@ouce.ox.ac.uk>> wrote: Hi all, I have a file, say, test.txt, which contains the following information. I'm trying to read in the

[R] reading in file with different row length

2010-05-06 Thread Muhammad Rahiz
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

Re: [R] question about 'write.table'

2010-05-05 Thread Muhammad Rahiz
This could work out <- c() for (a in 1:10){ out[a] <- paste("loci",a,sep="") write.table(out[a],file=out[a],row.names=FALSE,col.names=FALSE)} Muhammad karena wrote: I have a question about the "write.table" I have 100 data.frames, loci1, loci2, loci3.,loci100. now, I want

Re: [R] How to replace all values in a data.frame with another ( not 0) value

2010-05-04 Thread Muhammad Rahiz
Hi Nevil, You can try a method like this x <- c(rnorm(5),rep(NA,3),rnorm(5)) # sample data dat <- data.frame(x,x) # make sample dataframe dat2 <- as.matrix(dat) # conver to matrix y <- which(is.na(dat)==TRUE) # get index of NA values dat2[y] <- "

Re: [R] How to replace all values in a data.frame with another ( not 0) value

2010-05-04 Thread Muhammad Rahiz
000/000 returns NaN, which is no different than NA unless you want it as string i.e. "000/000" Muhammad Lanna Jin wrote: Try: "x[which(is.na(x)),] <- 000/000", where is x is your data frame - Lanna Jin lanna...@gmail.com 510-898-8525 __

Re: [R] adding year information to a scatter plot

2010-05-02 Thread Muhammad Rahiz
Hi Ozan, The {calibrate} package allows you to do that. install.packages("calibrate") library(calibrate) df=data.frame(year=c(2001,2002,2003),a=c(8,9,7),b=c(100,90,95)) df plot(b~a,data=df) textxy(df$a,df$b,df$year) Muhammad On 05/02/2010 08:25 PM, Ozan Bakis wrote: Hi R users, I would lik

Re: [R] Scree diagram,

2010-05-02 Thread Muhammad Rahiz
1) I believe you wanted a scree plot which shows the percentage of variance explained (y-axis) versus the principal components (x-axis). To do that, all you needs a simple plot(x,y) function where x = pc and y = variance. It is called a scree plot because the plot looks like a scree on the side

Re: [R] Intersection for two curves

2010-04-24 Thread Muhammad Rahiz
[1] + x*coef(fm)[2]} in1 <- optimize(f=function(x) abs(int(x)-n),c(0,120)) abline(v=in1$minimum,col="red",lty=2) abline(h=n,col="red",lty=2) Muhammad David Winsemius wrote: On Apr 23, 2010, at 8:06 PM, Muhammad Rahiz wrote: Thanks David & Peter, The locator() work

Re: [R] Intersection for two curves

2010-04-23 Thread Muhammad Rahiz
,120), abs(int(ds)-n)) abline(v=in1$minimize) thanks, Muhammad On 04/23/2010 07:32 PM, Peter Ehlers wrote: On 2010-04-23 11:46, David Winsemius wrote: On Apr 23, 2010, at 1:06 PM, Muhammad Rahiz wrote: Does anyone know of a method that I can get the intersection where the red and bl

[R] Intersection for two curves

2010-04-23 Thread Muhammad Rahiz
Does anyone know of a method that I can get the intersection where the red and blue curves meet i.e. the value on the x-axis? x <- 1:10 y <- 10:1 plot(x,y) abline(lm(y~x),col="blue") abline(h=2.5,col="red") Muhammad __ R-help@r-project.org mailing li

Re: [R] Error in plotting non-linear regression

2010-04-22 Thread Muhammad Rahiz
It now works. Thanks both. Muhammad Peter Ehlers wrote: On 2010-04-22 11:09, Muhammad Rahiz wrote: Hello everyone, I'm trying to draw the non-linear regression curve to look at the distance decay relationship between distance and correlation values. But I'm not able to plot

Re: [R] simple question

2010-04-22 Thread Muhammad Rahiz
Hi Gabriele, This is one way but I'm sure that there is an optimal way of doing so... x <- c("A","B","C","C","C","C","C","B","B") name <- unique(x) # get unique characters freq <- c() for (a in 1:length(name)){ freq[a] <- sum(x==name[a])}# get frequency out <- cbind(name,freq)

[R] Error in plotting non-linear regression

2010-04-22 Thread Muhammad Rahiz
Hello everyone, I'm trying to draw the non-linear regression curve to look at the distance decay relationship between distance and correlation values. But I'm not able to plot the curve as I'm struggling with the following error ("parameters without starting value in 'data': x") and found no

[R] using which to select range of values

2010-04-22 Thread Muhammad Rahiz
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 ___

[R] array manipulation

2010-04-14 Thread Muhammad Rahiz
Hello listeRs, I'm trying to make a square radius around a given reference point. So given the following array, how can I manipulate it so that x0 <- array(1,dim=c(5,5)) x0 1 1 1 1 1 1 1 1 1 1 1 1 *1* 1 1 1 1 1 1 1 1 1 1 1 1 becomes into 3 3 3 3 3 3 2 2 2 3 3 2 *1* 2 3 3 2 2 2 3 3 3 3 3 3

Re: [R] Odp: plot area: secondary y-axis does not display well

2010-04-02 Thread Muhammad Rahiz
Thanks Ivan, Jim and Petr. The output turns out as desired after I've taken your suggestions. Muhammad __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-

[R] plot area: secondary y-axis does not display well

2010-04-02 Thread Muhammad Rahiz
Dear useRs, I'm having a slight problem with plotting on 2 axes. While the following code works alright on screen, the saved output does not turn out as desired i.e. the secondary y-axis does not display fully. Just run the code and look at image output. Suggestions please... thanks, Muhamm

Re: [R] one way to write scripts in R

2010-03-29 Thread Muhammad Rahiz
I've been calling R from shell using the following (as example) ... #!/bin/bash for dir in $(ls *.txt); do R CMD BATCH script.R done Muhammad Tsjerk Wassenaar wrote: Hi, That seems quite neat. To make it a bit more flexible, and maybe do some argument acrobatics with bash, you could change

Re: [R] insert/copy skipped lines to output

2010-03-28 Thread Muhammad Rahiz
rner yllcorner cellsize NODATA_value 180.00 290.00 -20.00 -20.00 5000.00 -9999.00 1 3 5 2 4 6 Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment, Unive

Re: [R] insert/copy skipped lines to output

2010-03-28 Thread Muhammad Rahiz
Yes, it works. Just wondering if the technique can be optimized... David Winsemius wrote: On Mar 28, 2010, at 12:51 PM, Muhammad Rahiz wrote: Dear Jannis, Thanks for the tip. It works but I'd like to improve on the way I did it. x <- array(1:50,dim=c(10,10)) # data h1 <

Re: [R] insert/copy skipped lines to output

2010-03-28 Thread Muhammad Rahiz
this write() command first with your additional data (header data) and then with the "real" data and append=TRUE, your information ends up in the same file. HTH Jannis Muhammad Rahiz schrieb: Hello all, I'd like some advise on this. When I read my files, I pass the argument,

[R] insert/copy skipped lines to output

2010-03-27 Thread Muhammad Rahiz
Hello all, I'd like some advise on this. When I read my files, I pass the argument, skip=6, to skip 6 lines of header information. After performing the desired calculations, I have the output. Now I want to copy the 6 lines of skipped information to the output. What I've been doing so far is

Re: [R] Summing with NA

2010-03-24 Thread Muhammad Rahiz
Slightly longer method, but works as well. z <- c(-12,-9) e <- c(-2,0) k <- c(NA,NA) x <- c(z,e,k) x1 <- which(x!="NA",arr.ind=TRUE) # get elements which are not NA x2 <- x[x1] sum(x2) [1] -23 -- Muhammad tj wrote: Hi all, May I request for your help if you have time and if you have an i

Re: [R] Converting date format

2010-03-24 Thread Muhammad Rahiz
The following functions may help; strptime() ISOdate() Muhammad Hosack, Michael wrote: R community: Hello, I would to like to convert a character date variable from %m/%d/%Y to %m/%d/%y. Any advice would be greatly appreciated. I have tried functions for changing the formatting and rem

[R] Frequency: NA values returns zero

2010-02-23 Thread Muhammad Rahiz
Hi all, I created the following script to make a frequency count for multi-dimenstioanl array. There is no problem with the results except for the NA values which returns 0. Now, I don't want NA to return 0 but to return as NA. This is because I'm dealing with gridded data in which the NODAT

Re: [R] Create matrix with subset from unlist

2010-02-01 Thread Muhammad Rahiz
: Correct me if I'm wrong, but isn't this the solution I gave?? On Fri, Jan 29, 2010 at 9:43 AM, Muhammad Rahiz mailto:muhammad.ra...@ouce.ox.ac.uk>> wrote: Thanks David & Dennis, I may have found something. Given that the object xx is the product of unlist(x),

Re: [R] Create matrix with subset from unlist

2010-01-29 Thread Muhammad Rahiz
simple test > mode(xx3) > "numeric" Am I doing this right? Muhammad -- Muhammad Rahiz wrote: Thanks David & Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do,

Re: [R] Create matrix with subset from unlist

2010-01-29 Thread Muhammad Rahiz
Thanks David & Dennis, I may have found something. Given that the object xx is the product of unlist(x), to create a 2x2 matrix with subsets, I could do, > y <- matrix(xx[c(1:4)], 2, 2). This returns, [,1] [,2] [1,] -27.3 14.4 [2,] 29.0 -38.1 If I do, > y2 <- matrix(xx[c(5:8)],2,2

[R] Create matrix with subset from unlist

2010-01-29 Thread Muhammad Rahiz
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]] V1V2

[R] (list) object cannot be coerced to type 'double'

2010-01-26 Thread Muhammad Rahiz
Dear all, My script returns the following error: Error in storage.mode(test) <- "logical" : (list) object cannot be coerced to type 'double' I've looked around and some suggest that it could be the way data have been imported. For my case, I don't think it is such. Rather I think it has to

[R] Drought severity index: Excel to R

2010-01-16 Thread Muhammad Rahiz
o the dummy file, d, which I created (which apparently didn't work). I hope my explanation makes sense. thanks. Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Enviro

Re: [R] Drought Severity Index (DSI)

2010-01-12 Thread Muhammad Rahiz
Thanks Steve! Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +4

Re: [R] Drought Severity Index (DSI)

2010-01-12 Thread Muhammad Rahiz
e: +44 (0)7854-625974 Email: muhammad.ra...@ouce.ox.ac.uk Jim Lemon wrote: On 01/12/2010 07:21 PM, Muhammad Rahiz wrote: Does anyone have the code to calculate the drought severity index? Hi Muhammad, If you mean "does anyone have the algorithm?" it seems pretty hard

[R] Drought Severity Index (DSI)

2010-01-12 Thread Muhammad Rahiz
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, Ox

Re: [R] Question on Reduce + rollmean

2010-01-07 Thread Muhammad Rahiz
Yes, should be 1. out[[i]], instead of t[[i]]. 2. x1[c(i:(i+1))] # For this case, I was trying out the rolling sum. Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environ

Re: [R] Question on Reduce + rollmean

2010-01-07 Thread Muhammad Rahiz
("+", x1[c(i:i+1)]) } Muhammad Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment South Parks Road, Oxford, OX1 3Q

Re: [R] Increment in loop - OK

2010-01-07 Thread Muhammad Rahiz
This works. m <- matrix(1:3,3,3) x1 <- list(m, m+1, m+2, m+3, m+4) out <- list() for (i in 1:4){ t[[i]] <- Reduce("+", x1[c(i:i+1)]) } Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Resea

[R] Increment in loop

2010-01-06 Thread Muhammad Rahiz
s 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, m+2, m+3, m+4) Thanks. Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the

Re: [R] Question on Reduce + rollmean

2010-01-04 Thread Muhammad Rahiz
Thanks Gabor, It works alright. But is there alternative ways to perform rollmean apart from permutating the data? Possibly combining the Reduce and rollmean functions? The easiest but traditional way is > (x[[1]]+x[[2]]) / 2 > (x[[2]]+x[[3]]) / 2 Muhammad Rahiz | Doctoral Stud

Re: [R] Question on Reduce + rollmean

2010-01-02 Thread Muhammad Rahiz
x[[2]] ) / 2 ( x[[2]] + x[[3]] ) / 2 ... and so on. The desired output will return 2.5 2.5 2.5 3.5 3.5 3.5 4.5 4.5 4.5 5.5 5.5 5.5 6.5 6.5 6.5 7.5 7.5 7.5 Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment

[R] Question on Reduce + rollmean

2010-01-02 Thread Muhammad Rahiz
The moving average is to be performed on 1,4,7 = (1+4)/2 , (4+7)/2 2,5,8 = .. 3,6,9 = .. Thanks Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment, Univer

[R] select elements and transpose

2009-12-30 Thread Muhammad Rahiz
oks something like the following; 1 10 19 2 11 20 3 12 21 and so on.. Thanks.. -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre

Re: [R] To export results

2009-12-28 Thread Muhammad Rahiz
> write.table(x2, "filename.txt", col.name=FALSE, row.name=FALSE) # where x2 = variable you want to save Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Env

[R] Scaling error

2009-12-27 Thread Muhammad Rahiz
hich is OK for a set of test data but not for my actual dataset. At the moment, I'm thinking of something in the lines of a for loop function i.e. for (i in ...){ statement... } Is there a syntax in the for loop that allows me to select the column/row in the file? Thanks. -- Muhammad R

Re: [R] if else does not return right value

2009-12-26 Thread Muhammad Rahiz
ix(read.table("test.txt")) Original code; if (x < 20){ y <- x + 100 # statement 1a ... # statement 1b } else { y <- x -100 # statement 2a ... # statement 2b } New code: n0 <- x + 100 n1 <- n0 + 0 m0 <- x - 100 m1 <- m0 - 0 ifelse(x < 20, n1, m1) Muhammad

[R] if else does not return right value

2009-12-26 Thread Muhammad Rahiz
h I don't know what it means the condition has length > 1 and only the first element will be used The problem is solved if I use the ifelse function but I want to specify the code as following; if (/condition/) { /statement 1a statement 1b /} else { /statement 2a statement 2b /} Thank

[R] Object of type 'closure' not subsettable - OK

2009-12-21 Thread Muhammad Rahiz
Thanks Petr, Barry & David for your useful comments. Given d2[[i]] <- f[[i]] - m The problem lies in how I define the object, d2[[i]], which I managed to resolve by > d2 <- list() -- Muhammad Rahiz | Doctoral Student in Regional Cli

Re: [R] Object of type 'closure' not subsettable

2009-12-21 Thread Muhammad Rahiz
- m If I run the following, the error is gone but I'm not getting the output for each individual file I require d2 <- f[[i]] - m The issue is, how do I make d2 subsettable? Thanks. Muhammad Muhammad Rahiz | Doctoral Student in Regional Climate Modeling

[R] Object of type 'closure' not subsettable

2009-12-20 Thread Muhammad Rahiz
t;- file[[i]] - mean It works OK when I typed into the terminal the following after running the script. > for (j in 1:3) print (file[[j]]-mean) Thanks. Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Resear

[R] Recall: Problem with sequence in loop

2009-12-20 Thread Muhammad Rahiz
pply(list, read.table) mean <- (Reduce("+", file)) myfile1 <- paste(strsplit(seq[[i]], "\\.")[[1]][1], "sum.txt", sep=".") write.table(mean, file=myfile1, row.names=FALSE, col.names=FALSE) } - Muhammad Rahiz wrote: Hi all, I've got a list

[R] Problem with sequence in loop

2009-12-20 Thread Muhammad Rahiz
9/txt/x.djf", seq) file <- lapply(list, read.table) mean <- (Reduce("+", file))/3 } When I call > objects() > list [1] "2006.01.txt.h" "2006.02.txt.h" "2006.12.txt.h" The listed files are the last files in the sequence. Am I doing the loo

Re: [R] Output multiple files

2009-12-08 Thread Muhammad Rahiz
Code works fine. Thanks! 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)

[R] Output multiple files

2009-12-07 Thread Muhammad Rahiz
ames=FALSE, col.names=FALSE) } Thanks. -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment South Parks Road, Oxford, OX1 3Q

[R] Standard deviation for each element in a set of matrices

2009-12-04 Thread Muhammad Rahiz
cell in the file (I'm using gridded data). The desired output is Output 3 3 3 3 3 3 3 3 3 Thanks. Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography

[R] Arithmetic on multiple files

2009-12-02 Thread Muhammad Rahiz
9 9 9 Muhammad -- Muhammad Rahiz | Doctoral Student in Regional Climate Modeling Climate Research Laboratory, School of Geography & the Environment Oxford University Centre for the Environment South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +4