[R] Overlaying two png?

2010-10-15 Thread steven mosher
I have a program that creates a Png file using Rgooglemap with an extent (lonmin,lonmax,latmin,latmax) I also have a contour plot of the same location, same extent, same sized (height/width) png file. I'm looking for a way to make the contour semi transparent and overlay it on the google map (

[R] Beginner question on bar plot

2010-10-15 Thread steven mosher
I've read a number of examples on doing a multiple bar plot, but cant seem to grasp how they work or how to get my data into the proper form. I have two variable holding the same factor The variables were created using a cut command, The following simulates that A - 1:100 B - 1:100 A[30:60] -

Re: [R] Reading in a tab delimitated file

2010-10-27 Thread steven mosher
if your data for the rest of the file looks like this then read.fwf will work. depending which vars you want to pull) widths= c(18,32,41) E-CBIL-28-raw-cel-1435145228.cel1 would pull 3 vars, E-CBIL-28-raw-cel-; 1435145228.cel;1 widths -c(32,41) E-CBIL-28-raw-cel-1435145228.cel;1 you

Re: [R] Best IDE for R

2010-10-27 Thread steven mosher
Thanks for the pointer, After looking at the many folders of R code I have I decided it was time to start working in an IDE and also getting my stuff under version control ( for my own sanity) I'll have a look at Geany.. for version control.. not so sure. On Wed, Oct 27, 2010 at 12:14 PM, Liviu

Re: [R] doubt in climate variability analysis in R! - code

2010-10-31 Thread steven mosher
Ok I downloaded it and showed you how to get your data out. How to read it into a raster brick, how to plot the data, how to get the mean rainfall of every day.lots more you can do. there is a bad bit of data in the last time step. check my blog. In the future what you should do is write code

[R] Strings from different locale

2010-11-01 Thread steven mosher
I'm doing some test processing of a cvs file that appears to use a different locale from my machine. I get the following warning: input string 1 is invalid in this locale My locale is US. Is this simply a matter of changing my locale to 'all; locales? I don't know what locale the string is

Re: [R] spliting first 10 words in a string

2010-11-02 Thread steven mosher
Thanks david. Matevz, maybe I can help explain by doing a very simple and brute force approach as opposed to the way david did it. But you should learn his methods. I will just do a subset of your problem and if you understand how it works then you should be able to get something done and

Re: [R] splitting First 10 words in a string

2010-11-02 Thread steven mosher
differing number of rows: 22928, 10« What am I doing wrong? Thnks, m *From:* steven mosher [mailto:mosherste...@gmail.com] *Sent:* Tuesday, November 02, 2010 8:45 PM *To:* David Winsemius *Cc:* Matevž Pavlič; Gaj Vidmar; r-h...@stat.math.ethz.ch *Subject:* Re: [R] spliting first 10

Re: [R] splitting First 10 words in a string

2010-11-02 Thread steven mosher
Line should be: first=second=third=fourth=fifth=sixth=seventh=eighth=ninth=tenth-vector(length=nrow( sent)) sorry cut and past error On Tue, Nov 2, 2010 at 3:32 PM, steven mosher mosherste...@gmail.comwrote: That's easy you are confusing the dummy code I sent. Do this: lit-read.csv

Re: [R] spliting first 10 words in a string

2010-11-02 Thread steven mosher
just merge the data.frames back together. use merge or cbind() cbind will be easier DF1 - data.frame(x,y,z) DF2 -data.frame(DF1$x) # copy a column then you added columns to DF2 just put them back together DF3 -cbind(DF2,DF1$y,DF$z) if you spend more time with R you will be able to do things

[R] Reverting to previous version

2010-11-12 Thread steven mosher
R 2.12 is not functioning for me On the MAC what the most painless way of reverting [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
I would use RCurl. if you have, for example, the url of an ftp site you can merely do a getURL() and the contents will be returned. That call will return data that can be coerced into a data.frame that will look like a directory structure listing the file names. If you need code just ask, but

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
using RCurl getFtpList - function(ftp){ # the structure returned is dependent on the ftp site as there are # various formats for directory listings dependent upon the server # and the OS. you will need to play with this. # have a look at the ftp with your browser first and

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
AM, Baoqiang Cao bqcaom...@gmail.com wrote: Thanks Steven! It is excellent code indeed! On Tue, Nov 30, 2010 at 11:26 AM, steven mosher mosherste...@gmail.com wrote: I would use RCurl. if you have, for example, the url of an ftp site you can merely do a getURL() and the contents

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
[ ,1],Time=dir[ ,2],stringsAsFactors=FALSE) closeAllConnections() return(out) } On Tue, Nov 30, 2010 at 9:56 AM, Baoqiang Cao bqcaom...@gmail.com wrote: Thanks Steven! It is excellent code indeed! On Tue, Nov 30, 2010 at 11:26 AM, steven mosher mosherste...@gmail.com wrote: I would use

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
) { #download.file failed } #no error message though 2) Henrique Dallazuanna and Steven Mosher both suggested using RCurl, here is an example code from Henrique for checking if a file exists on a server: library(RCurl) h = basicHeaderGatherer() Lines - getURI(http://www.pdb.org/pdb/files/2J0S.1001

[R] Summing over intervals

2010-07-15 Thread steven mosher
Given a matrix of MxN want to take the means of rows in the following fashion m-matrix(seq(1,80),ncol=20, nrow=4) result-matrix(NA,nrow=4,ncol=20/5) result[,1]-apply(m[,1:5],1,mean) result[,2]-apply(m[,6:10],1,mean) result[,3]-apply(m[,11:15],1,mean) result[,4]-apply(m[,16:20],1,mean)

Re: [R] Summing over intervals

2010-07-15 Thread steven mosher
, mean), ncol=ncol(m)/ncol(m2), byrow=TRUE) result -- Patrick Rogers Dept. of Political Science University of California, San Diego On Jul 15, 2010, at 2:39 AM, steven mosher wrote: Given a matrix of MxN want to take the means of rows in the following fashion m-matrix(seq(1,80),ncol=20

[R] Summing by index

2010-07-30 Thread steven mosher
# build a sample data frame illustrating the problem ids-c(rep(1234,5),rep(5436,3),rep(7864,4)) years-c(seq(1990,1994,by=1),seq(1991,1993,by=1),seq(1990,1993,by=1)) data-seq(14,25,by=1) data[6]-NA DF-data.frame(Id=ids,Year=years,Data=data) DF Id Year Data 1 1234 1990 14 2 1234 1991

Re: [R] Summing by index

2010-07-30 Thread steven mosher
ha. that was a stupid mistake. Thanks. On Fri, Jul 30, 2010 at 11:46 AM, David Winsemius dwinsem...@comcast.netwrote: On Jul 30, 2010, at 2:41 PM, steven mosher wrote: # build a sample data frame illustrating the problem ids-c(rep(1234,5),rep(5436,3),rep(7864,4)) years-c(seq(1990,1994

Re: [R] Summing by index

2010-07-30 Thread steven mosher
, at 2:41 PM, steven mosher wrote: # build a sample data frame illustrating the problem ids-c(rep(1234,5),rep(5436,3),rep(7864,4)) years-c(seq(1990,1994,by=1),seq(1991,1993,by=1),seq(1990,1993,by=1)) data-seq(14,25,by=1) data[6]-NA DF-data.frame(Id=ids,Year=years,Data=data) DF Id Year Data

Re: [R] Summing by index

2010-07-30 Thread steven mosher
very slick Thx. On Fri, Jul 30, 2010 at 12:44 PM, Wu Gong w...@mtmail.mtsu.edu wrote: Hi, R has a buildin function ?rowsum rowsum(DF$Data,DF$Id,na.rm=T) - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/Summing-by-index-tp2308332p2308411.html Sent

[R] Data frame reordering to time series

2010-08-07 Thread steven mosher
Given a data frame, or it could be a matrix if I choose to. The data consists of an ID, a year, and data for all 12 months. Missing values are a factor AND missing years. Id-c(rep(67543,4),rep(12345,3),rep(89765,5)) Years-c(seq(1989,1992,by =1),1991,1993,1994,seq(1991,1995,by=1))

Re: [R] Data frame reordering to time series

2010-08-07 Thread steven mosher
at 4:49 PM, steven mosher mosherste...@gmail.com wrote: Given a data frame, or it could be a matrix if I choose to. The data consists of an ID, a year, and data for all 12 months. Missing values are a factor AND missing years. Id-c(rep(67543,4),rep(12345,3),rep(89765,5)) Years-c(seq

Re: [R] Data frame reordering to time series

2010-08-07 Thread steven mosher
Jun 1990NA 21.0NA Jul 1990NA 21.0NA Aug 1990NA 21.0NA Sep 1990NANANA Oct 1990NANANA Nov 1990NANANA Dec 1990NANANA Jan 1991 54.0NA 12.0 Feb 1991 27.0NA 6.0 ... On Sat, Aug 7, 2010 at 5:09 PM, steven mosher

Re: [R] Data frame reordering to time series

2010-08-08 Thread steven mosher
and those 7000 get averaged and combined in different ways On Sat, Aug 7, 2010 at 8:45 PM, Gabor Grothendieck ggrothendi...@gmail.comwrote: On Sat, Aug 7, 2010 at 9:18 PM, steven mosher mosherste...@gmail.com wrote: Very Slick. Gabor this is a Huge speed up for me. Thanks. ha, Now I want

Re: [R] Data frame reordering to time series

2010-08-08 Thread steven mosher
AM, steven mosher mosherste...@gmail.com wrote: In the real data the months are all complete, but the years can be missing. So years can be missing up front, in the middle, at the end. but if a year is present than every month has a value or NA. To create regular R ts I had to plow

Re: [R] Data frame reordering to time series

2010-08-08 Thread steven mosher
this is the change from months to the (1)... On Sun, Aug 8, 2010 at 8:55 AM, Gabor Grothendieck ggrothendi...@gmail.comwrote: On Sun, Aug 8, 2010 at 11:21 AM, steven mosher mosherste...@gmail.com wrote: Ok, I'm a bit confused by what you mean by regularly spaced After I do the do.call I do get

[R] nested 'by'

2010-08-09 Thread steven mosher
Assuming a data frame or matrix with two columns representing variable that you want to aggregate over. you want to calculate column means, by year, for each Id example-data.frame(id=c(rep(12345,5),rep(54321,6),rep(45678,7)),Year=rep(seq(1900,1902,by=1),6), x=seq(1,18,by=1),y=seq(18,1,by=-1))

Re: [R] nested 'by'

2010-08-09 Thread steven mosher
That works. Thanks On Mon, Aug 9, 2010 at 7:55 AM, Henrique Dallazuanna www...@gmail.comwrote: Try this: aggregate(example[c('x', 'y')], example[c('id', 'Year')], 'mean') On Mon, Aug 9, 2010 at 11:46 AM, steven mosher mosherste...@gmail.comwrote: Assuming a data frame or matrix with two

[R] sweep and zoo objects

2010-08-11 Thread steven mosher
rc-list(c( 123,321,234,543,654,768,986,987,246,284),c(Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)) # the matrix has rownames that are used as identifiers and columns # of time. 1 years worth of data. Thats the native format test-matrix(seq(1,120, by=1), nrow=10,dimnames=rc) test Jan

[R] Sweeping a zoo series

2010-08-11 Thread steven mosher
Given a long zoo matrix, the goal is to sweep out a statistic from the entire length of the sequences. longzoomatrix-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,+))) cnames-c(12345,23456,34567,45678,56789,67890) colnames(longzoomatrix)-cnames longzoomatrix[1:24,]

Re: [R] Sweeping a zoo series

2010-08-11 Thread steven mosher
, 2010 at 11:21 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Aug 11, 2010 at 12:22 PM, steven mosher mosherste...@gmail.com wrote: Given a long zoo matrix, the goal is to sweep out a statistic from the entire length of the sequences. longzoomatrix-zoo(matrix(rnorm(720

[R] Creating list from a long vector

2010-08-14 Thread steven mosher
Stupid question, but its been a long night. If I have a long vector how can I turn it into a list of the same length x-rep(seq(1,100,by=1),each=10) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] Creating list from a long vector

2010-08-14 Thread steven mosher
Thx, I see my problem. more sleep required On Sat, Aug 14, 2010 at 9:25 AM, Romain Francois romain.franc...@dbmail.com wrote: Le 14/08/10 18:22, steven mosher a écrit : Stupid question, but its been a long night. If I have a long vector how can I turn it into a list of the same length

[R] Trouble loading saved Rdata

2010-08-14 Thread steven mosher
In the particular application I have I save test.Rdata to a sub directory dir-Example dir.create(dir) test-data.frame(a=c(1,2,3),b=c(3,4,5) full-file.path(dir,test.Rdata,fsep=.Platform$file.sep) save(test,file=full) load(full) returns NULL it works fine when the object is saved to the working

Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com wrote: In the particular application I have I save test.Rdata to a sub directory dir-Example dir.create(dir) test-data.frame(a=c(1,2,3),b=c(3,4,5) full-file.path(dir,test.Rdata,fsep=.Platform$file.sep) save(test,file=full

Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
you can report the results of sessionInfo() Cheers, Josh On Sat, Aug 14, 2010 at 5:14 PM, steven mosher mosherste...@gmail.com wrote: In the particular application I have I save test.Rdata to a sub directory dir-Example dir.create(dir) test-data.frame(a=c(1,2,3),b=c(3,4,5) full

Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
On Sun, Aug 15, 2010 at 12:06 AM, steven mosher mosherste...@gmail.com wrote: Did you exit R and then return? fname-test.Rdata full-file.path(Example,fname,fsep=.Platform$file.sep) full [1] Example/test.Rdata load(full) test NULL sessionInfo() R version 2.11.1 (2010-05-31

Re: [R] Trouble loading saved Rdata

2010-08-15 Thread steven mosher
, at 3:06 AM, steven mosher wrote: Did you exit R and then return? fname-test.Rdata full-file.path(Example,fname,fsep=.Platform$file.sep) full [1] Example/test.Rdata load(full) test NULL I am unable to reproduce the problem (after correcting two different syntactic errors in the initial

[R] differecing a zoo series

2010-08-20 Thread steven mosher
A quick question x - as.yearmon(2000 + seq(0, 23)/12) x [1] Jan 2000 Feb 2000 Mar 2000 Apr 2000 May 2000 Jun 2000 Jul 2000 Aug 2000 Sep 2000 Oct 2000 Nov 2000 Dec 2000 Jan 2001 [14] Feb 2001 Mar 2001 Apr 2001 May 2001 Jun 2001 Jul 2001 Aug 2001 Sep 2001 Oct 2001 Nov 2001 Dec 2001

[R] merging two maxtrices

2010-09-05 Thread steven mosher
j-matrix(nrow=10,ncol=10) k-matrix(seq(1:50), ncol=10) row.names(k) - seq(2,10,by=2) j [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA NA NA NA NA NA NANA [2,] NA NA NA NA NA NA NA NA NANA [3,] NA NA NA NA NA

Re: [R] merging two maxtrices

2010-09-05 Thread steven mosher
35 40 4550 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of steven mosher Sent: Sunday, 5 September 2010 5:10 PM To: r-help Subject: [R] merging two maxtrices j-matrix(nrow=10,ncol=10) k-matrix(seq(1:50), ncol

Re: [R] merging two maxtrices

2010-09-05 Thread steven mosher
NA NA NA NA NA NANA 105 10 15 20 25 30 35 40 4550 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of steven mosher Sent: Sunday, 5 September 2010 5:10 PM To: r-help Subject: [R] merging

Re: [R] If then else with command for

2010-09-14 Thread steven mosher
not sure how you wanted sampling of x R-142 color-rep(0,142) for(i in 1:R){ y-sample(x,142,replace=FALSE) onebit- as.numeric(3471 %in% y) twobit-as.numeric(6720 %in% y)*2 fourbit-as.numeric(6263 %in% y)*4 colorbit-onebit+twobit+fourbit+1 color[i]-colorbit } On Tue, Sep 14, 2010 at

Re: [R] How to uncompress a gz file in R

2010-09-15 Thread steven mosher
Wongsang, Just to be clear R.utils is different than utils As Henrik notes gunzip has been in R.utils ( see http://cran.r-project.org/) for some time. It works like a champ. R.utils is a great package. On Wed, Sep 15, 2010 at 9:30 AM, Wonsang You y...@ifn-magdeburg.de wrote: Dear Henrik,

Re: [R] Get File Names in Folder, Read Files, Update, and Write

2010-09-15 Thread steven mosher
...@phatrasecurities.com *From:* steven mosher [mailto:mosherste...@gmail.com] *Sent:* Thursday, September 16, 2010 2:29 AM *To:* Suphajak Ngamlak *Subject:* Re: [R] Get File Names in Folder, Read Files, Update, and Write Import-C:/A0810.RSK Table-read.table(file= Import, sep = ,, head=TRUE

Re: [R] How to uncompress a gz file in R

2010-09-16 Thread steven mosher
you are welcome. Henrik's package is an great piece of work. It is worth the time to read through the whole thing and see how you can improve your programs by using other features as well. On Thu, Sep 16, 2010 at 2:16 AM, Wonsang You y...@ifn-magdeburg.de wrote: Dear Henrik and Steven, Thank

Re: [R] Substitute NAs by zero

2010-09-20 Thread steven mosher
v-c(1,2,3,4,5,6,7,8,97,6,5,4,NA,NA) b-zoo(v) b 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 97 6 5 4 NA NA b[is.na(b)]-0 b 1 2 3 4 5 6 7 8 9 10 11 12 13 14 1 2 3 4 5 6 7 8 97 6 5 4 0 0 is.zoo(b) [1] TRUE On Mon, Sep 20, 2010 at 2:37 AM, skan

[R] diagnosing download.file() problems

2010-09-21 Thread steven mosher
I'm accessing around 95 tar files on an FTP server ranging in size between 10 and 40MB a piece. while certainly can click on them and download them outside of R, I'd like to have my script do it. Retrieving the ftp directory with RCurl works fine (about 90% of the time) but downloading the

Re: [R] diagnosing download.file() problems

2010-09-21 Thread steven mosher
pills. i did note, however, some odd behavior with tryCatch, where statements after the finally={} were executed. Not sure if that deserves a bug report. On Tue, Sep 21, 2010 at 2:33 AM, Barry Rowlingson b.rowling...@lancaster.ac.uk wrote: On Tue, Sep 21, 2010 at 9:39 AM, steven mosher

Re: [R] get absolute file path

2010-09-26 Thread steven mosher
The package R.utils has a function to get absolutepath On Sun, Sep 26, 2010 at 1:00 AM, Sebastian Gibb li...@sebastiangibb.dewrote: Hello, I get a value which stores a relative file name. (I get it from another function, which I don't want to change.) e.g. fileName - ../data/2010-08.csv;

Re: [R] Script auto-detecting its own path

2010-10-04 Thread steven mosher
in the package R.utils getAbsolutePath() or you can do a file.list(.. full.names=TRUE, recursive=TRUE,pattern=(.R)) the rest will require grep and pulling the file name and directory path apart If its not evident just ask and I'll write something for you. basically you want a call

Re: [R] RE : R getting slower until it breaks...

2010-10-06 Thread steven mosher
I know its no consolation, but I have a similar issue with R on a MAC, also ploting out large numbers of raster layers. sometimes the problem lingers even after I clear the workspace, do gc() etc. Almost as if R wont ask for processor resources. weird. On Wed, Oct 6, 2010 at 12:06 PM, Bastien

Re: [R] RE : R getting slower until it breaks...

2010-10-06 Thread steven mosher
Thanks, haven't used valgrind in years, this should be fun. Steve On Wed, Oct 6, 2010 at 1:55 PM, Ben Bolker bbol...@gmail.com wrote: steven mosher moshersteven at gmail.com writes: I know its no consolation, but I have a similar issue with R on a MAC, also ploting out large

[R] Loss of precision in read.csv.

2010-10-09 Thread steven mosher
Given a csv file from this location Airports-http://www.ourairports.com/data/airports.csv; download.file(Airports,basename(Airports)) airports -read.csv(airports.csv,encoding=UTF-8) airports[1,] id ident type name latitude_deg longitude_deg elevation_ft continent

Re: [R] Loss of precision in read.csv.

2010-10-09 Thread steven mosher
at 1:33 PM, steven mosher mosherste...@gmail.com wrote: Given a csv file from this location Airports-http://www.ourairports.com/data/airports.csv; download.file(Airports,basename(Airports)) airports -read.csv(airports.csv,encoding=UTF-8) airports[1,] id ident type

Re: [R] Read from a website

2010-10-12 Thread steven mosher
Hmm, RCurl might have something on this. otherwise pull you can figure out their scheme and just construct the url from scratch. when you finish filling in the form, look at the url they construct. do it a few times and you can just emulate that. I've done that in the past without problems.

[R] Calculating a Maximum for a row or column with NA's

2010-04-17 Thread steven mosher
Is there a simple way to calculate the maximum for a row or column of a matrix when there are NA,s present. # given a matrix that has any number of NA per row m-matrix(c(seq(1,9)),nrow=3) m [,1] [,2] [,3] [1,]147 [2,]258 [3,]369 m[3,1]=NA m[1,]=NA m

Re: [R] Calculating a Maximum for a row or column with NA's

2010-04-17 Thread steven mosher
a large number of these -Inf.. I Was looking at maxtrixStats package but it still beta On Sat, Apr 17, 2010 at 10:01 PM, David Winsemius dwinsem...@comcast.netwrote: On Apr 18, 2010, at 12:16 AM, steven mosher wrote: Is there a simple way to calculate the maximum for a row or column of a matrix

Re: [R] Calculating a Maximum for a row or column with NA's

2010-04-17 Thread steven mosher
= TRUE))) [1] NA 8 9 See ?ifelse, ?all and ?max for more information. HTH, Jorge On Sun, Apr 18, 2010 at 12:16 AM, steven mosher wrote: Is there a simple way to calculate the maximum for a row or column of a matrix when there are NA,s present. # given a matrix that has any number of NA

Re: [R] Calculating a Maximum for a row or column with NA's

2010-04-18 Thread steven mosher
improvements. On Sun, Apr 18, 2010 at 2:47 AM, Henrik Bengtsson h...@stat.berkeley.eduwrote: On Sun, Apr 18, 2010 at 7:26 AM, steven mosher mosherste...@gmail.com wrote: Ya I got that result but fixing it was a mystery. especially since I will eventually want to subtract the row max from the row Min

[R] Noobie question on aggregate tapply and by

2010-04-25 Thread steven mosher
I have a 43MB dataframe ( 5 variables) and I'm trying to summarize subsets of the data. I've RTFM ( not very clear) and looked at a variety of samples but cant seem to figure out how to make these functions work. A sample of what I want to do would be this: ids-seq(1,50)

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread steven mosher
) -- On Sun, Apr 25, 2010 at 9:29 AM, steven mosher mosherste...@gmail.comwrote: I have a 43MB dataframe ( 5 variables) and I'm trying to summarize subsets of the data. I've RTFM ( not very clear) and looked at a variety of samples but cant

Re: [R] Noobie question on aggregate tapply and by

2010-04-25 Thread steven mosher
') DF$years - recode(DF$years, c(5,6,7)= '5-7') DF You may also want to have a look at the reshape and plyr packages. --- On Sun, 4/25/10, steven mosher mosherste...@gmail.com wrote: From: steven mosher mosherste...@gmail.com Subject: [R] Noobie question on aggregate tapply

[R] Tapply.

2010-04-25 Thread steven mosher
Having some difficulties with understanding how tapply works and getting return values I expect Data: dataframe. DF DF$Id $D $Year... Id D Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 11264402000 1 1980 NA NA NA NA NA 212 203 209 228 237 NA

Re: [R] Tapply.

2010-04-26 Thread steven mosher
I've tried both mean and colMean. I did success with one attempt using mean, however if only have 1 year and its a NA then I get NaN ( which I can replace). I'll keep trying. On Mon, Apr 26, 2010 at 12:26 AM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal

Re: [R] Tapply.

2010-04-26 Thread steven mosher
That fails: The manual says: tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE) ArgumentsXan atomic object, typically a vector.INDEXlist of factors, each of same length as X. The elements are coerced to factors by as.factorhttp://127.0.0.1:31214/library/base/help/as.factor . my error says:

Re: [R] Tapply.

2010-04-26 Thread steven mosher
230 8 1.33 1989 232 233 238 239 231 NaN 215 NaN NaN NaN NaN 238 Replace the NaNs with NAs and that should do it HTH, Dennis On Sun, Apr 25, 2010 at 9:52 PM, steven mosher mosherste...@gmail.comwrote: Having some difficulties with understanding how tapply works and getting return

Re: [R] Tapply.

2010-04-26 Thread steven mosher
PIKAL petr.pi...@precheza.cz wrote: Hi steven mosher mosherste...@gmail.com napsal dne 26.04.2010 10:21:37: That fails: The manual says: tapply(X, INDEX, FUN = NULL, ..., simplify = TRUE) Arguments X an atomic object, typically a vector. INDEX list of factors, each

Re: [R] Tapply.

2010-04-27 Thread steven mosher
Thanks dennis. Is there a book on R u could recommend. On Mon, Apr 26, 2010 at 7:12 PM, Dennis Murphy djmu...@gmail.com wrote: Hi: On Mon, Apr 26, 2010 at 8:01 AM, steven mosher mosherste...@gmail.comwrote: Thanks, I was trying to stick with the base package and figure out

Re: [R] Tapply.

2010-04-27 Thread steven mosher
, drop=FALSE]) str(df[,1:15]) Regards Petr Thanks. On Mon, Apr 26, 2010 at 2:43 AM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi steven mosher mosherste...@gmail.com napsal dne 26.04.2010 10:21:37: That fails: The manual says: tapply(X, INDEX, FUN

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
I was talking with another guy on the list about this very topic. A simple example would help. first a sample C struct, and then how one would do the equivalent in R. In the end i suppose one want to do a an 'array' of these structs, or list of the structs. On Sat, May 1, 2010 at 8:04 AM, Ted

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
Azua brave...@gmail.com wrote: On May 1, 2010, at 6:48 PM, steven mosher wrote: I was talking with another guy on the list about this very topic. A simple example would help. first a sample C struct, and then how one would do the equivalent in R. In the end i suppose one want to do

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
: On May 1, 2010, at 6:48 PM, steven mosher wrote: I was talking with another guy on the list about this very topic. A simple example would help. first a sample C struct, and then how one would do the equivalent in R. In the end i suppose one want to do a an 'array' of these structs

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
Winsemius dwinsem...@comcast.netwrote: On May 1, 2010, at 3:14 PM, steven mosher wrote: maybe I can illustrate the problem by showing how a c programmer might think about the problem and the kinds of mistakes 'we' ( I) make when trying to do this in R cstruct-function(int, bool){ + + myint

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
] [1] 130 TADA! On Sat, May 1, 2010 at 12:42 PM, David Winsemius dwinsem...@comcast.netwrote: On May 1, 2010, at 3:14 PM, steven mosher wrote: maybe I can illustrate the problem by showing how a c programmer might think about the problem and the kinds of mistakes 'we' ( I) make when trying

Re: [R] closest match in R to c-like struct?

2010-05-01 Thread steven mosher
thanks ted.. being new the R thsi has been a huge help, espececially on the Myint=myint thing... I assummed the name was just implicit. On Sat, May 1, 2010 at 1:19 PM, Ted Harding ted.hard...@manchester.ac.ukwrote: See below. On 01-May-10 19:14:08, steven mosher wrote: maybe I can

[R] Adding a header after the file is written

2010-05-03 Thread steven mosher
The situation arises where I open a file to write a data.frame to it. with write.table. multiple lines are written to the file and the file is kept in Append=TRUE mode. If one sets the col.names to the names of the variables being written, you have output that looks like this... name1 name2

Re: [R] Adding a header after the file is written

2010-05-03 Thread steven mosher
On Mon, May 3, 2010 at 5:19 PM, steven mosher mosherste...@gmail.com wrote: The situation arises where I open a file to write a data.frame to it. with write.table. multiple lines are written to the file and the file is kept in Append=TRUE mode. If one sets the col.names to the names

Re: [R] Adding a header after the file is written

2010-05-04 Thread steven mosher
thanks.. worked On Mon, May 3, 2010 at 3:24 PM, Ted Harding ted.hard...@manchester.ac.ukwrote: On 03-May-10 21:19:34, steven mosher wrote: The situation arises where I open a file to write a data.frame to it. with write.table. multiple lines are written to the file and the file is kept

[R] error in La.svd Lapack routine 'dgesdd'

2010-05-04 Thread steven mosher
Error in La.svd(x, nu, nv) : error code 1 from Lapack routine ‘dgesdd’ what resources are there to track down errors like this [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

[R] extracting a matched string using regexpr

2010-05-05 Thread steven mosher
Given a text like I want to be able to extract a matched regular expression from a piece of text. this apparently works, but is pretty ugly # some html test-/trtrth88958/ththAbcdsef/thth67.8S/thth68.9\nW/thth26m/th # a pattern to extract 5 digits pattern-[0-9]{5} # regexpr returns a start

Re: [R] extracting a matched string using regexpr

2010-05-05 Thread steven mosher
and we ask for the contents of the first component using [[1]]. # 1 - sub sub(.*(\\d{5}).*, \\1, test) # 2 - strapply - see http://gsubfn.googlecode.com library(gsubfn) strapply(test, \\d{5}, c)[[1]] On Wed, May 5, 2010 at 5:13 PM, steven mosher mosherste...@gmail.com wrote: Given a text

Re: [R] extracting a matched string using regexpr

2010-05-05 Thread steven mosher
://gsubfn.googlecode.com library(gsubfn) strapply(test, \\d{5}, c)[[1]] On Wed, May 5, 2010 at 5:13 PM, steven mosher mosherste...@gmail.com wrote: Given a text like I want to be able to extract a matched regular expression from a piece of text. this apparently works, but is pretty ugly

Re: [R] extracting a matched string using regexpr

2010-05-05 Thread steven mosher
/ththAbcdsef/thth67.8S/thth68.9\nW/thth26m/th sub(.*(\\d{5}).*, \\1, test) [1] 88958 R.version.string [1] R version 2.10.1 (2009-12-14) I also got the above in R 2.11.0 patched as well. On Wed, May 5, 2010 at 5:55 PM, steven mosher mosherste...@gmail.com wrote: test [1] /trtrth88958

Re: [R] extracting a matched string using regexpr

2010-05-05 Thread steven mosher
) Service Pack 2 On Wed, May 5, 2010 at 6:20 PM, steven mosher mosherste...@gmail.com wrote: Hmm. I have R11 just downloaded fresh. I'll reload a new session..and revert. I will note that I've had trouble with \\d which is why I was using [0-9] MAC here. On Wed, May 5, 2010 at 3:00 PM

[R] quick question on getting a listing of files on ftp site

2010-05-22 Thread steven mosher
Given a valid ftp address, is there a package that will allow me to get a listing of the files/directory structure on that site? RCurl looks to have this ability are there others? [[alternative HTML version deleted]] __ R-help@r-project.org

[R] quick question on ftp access

2010-05-22 Thread steven mosher
I'm looking for a function or package that will allow me to get a list of the files at an ftp site. RCurl looks promising. Are there other packages that have similar functionality [[alternative HTML version deleted]] __ R-help@r-project.org

[R] Matrix to Vector

2010-06-05 Thread steven mosher
Given a matrix of m*n, I want to reorder it as a vector, using a row major transpose. so: m-matrix(seq(1,48),nrow=6,byrow=T) m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]12345678 [2,]9 10 11 12 13 14 15 16 [3,] 17 18 19 20 21

Re: [R] Matrix to Vector

2010-06-05 Thread steven mosher
32 33 34 35 36 37 38 39 40 41 42 43 44 45 [46] 46 47 48 On Sat, Jun 5, 2010 at 11:17 AM, Henrique Dallazuanna www...@gmail.comwrote: Try this: as.vector(t(m)) On Sat, Jun 5, 2010 at 3:12 PM, steven mosher mosherste...@gmail.comwrote: Given a matrix of m*n, I want to reorder it as a vector

Re: [R] Matrix to Vector

2010-06-05 Thread steven mosher
I bet that is what I did. On Sat, Jun 5, 2010 at 11:54 AM, John Kane jrkrid...@yahoo.ca wrote: m-matrix(seq(1,48),nrow=6,byrow=T) as.vector(t(m)) gives me the correct result. Any chance you may have already transformed m ? --- On Sat, 6/5/10, steven mosher mosherste...@gmail.com wrote

[R] counting Na/not NA by groups by column

2010-06-09 Thread steven mosher
# create a matrix with some random NAs in it m-matrix(NA,nrow=15,ncol=14) m[,3:14]-52 m[13,9]-NA m[4:7,8]-NA m[1:2,5]-NA m[,2]-rep(1800:1804, by=3) y-order(m[,2]) m-m[y,] m[,1]-rep(1:3,by=5) m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,]1

Re: [R] counting Na/not NA by groups by column

2010-06-09 Thread steven mosher
, 2010 at 6:16 PM, Erik Iverson er...@ccbr.umn.edu wrote: Hello, steven mosher wrote: # create a matrix with some random NAs in it m-matrix(NA,nrow=15,ncol=14) m[,3:14]-52 m[13,9]-NA m[4:7,8]-NA m[1:2,5]-NA m[,2]-rep(1800:1804, by=3) y-order(m[,2]) m-m[y,] m[,1]-rep(1:3,by=5

Re: [R] working with zoo time index ??

2010-06-15 Thread steven mosher
Hi Gabor, Not sure where to report this, but Mac 10.5.8 R: 11.1 When you examine the zoo vignette and hit the back button, you get a hang. I havent tested with other vignettes and cant imagine that is is specific to yours FWIW. Did I mention that zoo is great. Thx for your work on it. On

[R] applying ifelse to dataframe

2010-06-22 Thread steven mosher
The following dataframe will illustrate the problem DF-data.frame(name=rep(1:5,each=2),x1=rep(A,10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1)) DF$x3[5]-50 # we have a data frame. we are interested in the columns x2,x3,x4 which contain sparse # values and many NA. DF name x1 x2

Re: [R] applying ifelse to dataframe

2010-06-22 Thread steven mosher
Thanks, the dataframe, is indeed clever at preserving its dimensions. I'll try your solution with the real data On Tue, Jun 22, 2010 at 12:23 M, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 22.06.2010 08:28:04: The following dataframe will illustrate

Re: [R] applying ifelse to dataframe

2010-06-22 Thread steven mosher
Hmm DF-data.frame(name=rep(1:5,each=2),x1=rep(A,10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1)) DF$x3[5]-50 mask-apply(sample,2,%in%, target) DF name x1 x2 x3 x4 1 1 A 10 NA 20 2 1 A 11 NA 21 3 2 A 12 NA 22 4 2 A 13 NA 23 5 3 A 14 50 24 6 3 A 15 NA

Re: [R] applying ifelse to dataframe

2010-06-22 Thread steven mosher
Thanks for the solution On Tue, Jun 22, 2010 at 1:02 AM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2010-06-22 1:45, steven mosher wrote: Hmm DF-data.frame(name=rep(1:5,each=2),x1=rep(A,10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1)) DF$x3[5]-50 mask-apply(sample,2

Re: [R] Why software fails in scientific research

2010-07-01 Thread steven mosher
Thomas, How popular is R inside of NOAA? On Thu, Jul 1, 2010 at 11:25 AM, Thomas Adams thomas.ad...@noaa.gov wrote: OK… My Grandfather, who was a farmer, was outstanding in his field… Cheers… Murray M Cooper, PhD wrote: For what its worth! A good friend who also happens to be

  1   2   >