Re: [R] calling in inverted commas

2014-04-12 Thread Frede Aakmann Tøgersen

Hi

Sigh I'm getting a headache seeing ugly formatted R code. Arun, your code is 
almost unreadable. Have a look at e.g. 
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Now to the substantial. Why not use the sprintf() function for formatting the 
url instead of the more involved approach using several gsub and regular 
expressions that not many people (including myself) easily understand.

## here is a small example using sprintf(), see ?sprintf
## %s is format specifier for string
exampleStr - west=%snorth=%seast=%ssouth=%s

sprintf(exampleStr, 1, 2, 3, 4)
##  [1] west=1north=2east=3south=4

## since % is used in format specification then if a literal % is needed in the 
string as here
## where you have e.g. %2F01% then escape those % with a %, i.e. % becomes %% 
in the string
## I have done that in urlPattern:
urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7prod_id=3B42_dailyaction=ASCII+Output

## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75)) 

fileDestination - c(C:/Temp)
fileNames - paste(precip, df2[,1], df2[,2], sep = _)
fileNames - paste(fileNames, txt, sep = .)
files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
download.file(queryUrl, files[i])
}

## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
 sep = , check.names = FALSE, stringsAsFactors = FALSE)

head(precip)


Here is another way using the url() function instead of download.file()

## Escaping the trouble with saving and reading files one can also do it this 
way
## having the dataframes in a named list
precipList - vector(list, nrow(df2))
names(precipList) - fileNames

for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
u - url(queryUrl, open = r)
precipList[[i]] - read.table(u, skip = 4, header = TRUE, na.strings = 
-.9,
 sep = , check.names = FALSE, stringsAsFactors = FALSE)
close(u)
}

str(precipList)

Have a nice day.


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of arun
 Sent: 12. april 2014 07:16
 To: r-help@r-project.org
 Subject: Re: [R] calling in inverted commas
 
 Hi,
 I noticed some special characters after sending.
 It should be:
 toreplace - gsub(.*\\.pl\\?(west\\=.*south=.*)\\params.*,\\1,Url1)
 end - gsub(.*south=.*(\\params.*),\\1,Url1)
 
 
 A.K.
 
 
 On Saturday, April 12, 2014 1:06 AM, arun smartpink...@yahoo.com
 wrote:
 HI,
 
 Not sure if this helps:
 df2 - data.frame(Col1=c(68.25, 68.75, 69.25), Col2=c(24.75, 25.25, 25.75))
 
 
 Url1 - http://disc2.nascom.nasa.gov/daac-
 bin/Giovanni/tovas/Giovanni_cgi.pl?west=68.25north=24.75east=68.25s
 outh=24.75¶ms=0%7C3B42_V7plot_type=Time+Plotbyr=1998bmo=01
 bdy=1eyr=2007emo=12edy=31begin_date=1998%2F01%2F01end_da
 te=2014%2F01%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax
 =yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRM
 M_V7∏_id=3B42_dailyaction=ASCII+Output
 
 
 toreplace - gsub(.*\\.pl\\?(west\\=.*south=.*)\\¶ms.*,\\1,Url1)
 begin - gsub((.*\\.pl\\?).*,\\1,Url1)
 end - gsub(.*south=.*(\\¶ms.*),\\1,Url1)
 
 vec2 - strsplit(toreplace,)[[1]]
 
 ##replace .csv with .txt and use write.table() if you need as text files.
 
 
 lapply(seq_len(nrow(df2)),function(i) { val1 -
 as.vector(rep(unlist(df2[i,]),2));replaced -
 do.call(paste,list(lapply(seq_along(vec2),function(i) gsub([-
 +]?(\\d*[.])?\\d+,val1[i],vec2[i])),collapse=)); UrlNew -
 paste0(begin,replaced,end); res -
 read.csv(UrlNew,header=TRUE,stringsAsFactors=FALSE,skip=4,sep=,check.
 names=FALSE);
 write.csv(res,file=paste0(file_,paste(val1[1:2],collapse=_),.csv),row.na
 mes=FALSE,quote=FALSE)})
 
 sapply(list.files(pattern=file_),function(x) {x1 -
 read.csv(x,header=TRUE,stringsAsFactors=FALSE,check.names=FALSE);
 dim(x1)[1]})
 #file_68.25_24.75.csv file_68.75_25.25.csv file_69.25_25.75.csv
 
 #                3652                 3652                 3652
 
 ### reading the downloaded file
 
 lapply(list.files(pattern=file_),function(x) {x1 -
 

Re: [R] Save file as Fixed Width using sprintf()

2014-04-12 Thread Frede Aakmann Tøgersen
Hi

Have a look at the write.fwf ( fixed width format) in gdata package.


 ### load package
 library(gdata)
 
 ### Create a sample data matrix
 set.seed(4324)
 myMat - matrix(rnorm(9), 3,3)
 
 ### cannot get it tp work with matrix so cast to dataframe
 write.fwf(as.data.frame(myMat), file = , sep = , colnames = FALSE)
-0.6464857-0.6289709-0.3129283
 1.4342941-0.6378252-1.6057577
 0.6456513 0.2481384-1.1617556
 
 ### same as before
 write.fwf(as.data.frame(myMat), file = , width = c(10,10,10), sep = , 
 colnames = FALSE)
-0.6464857-0.6289709-0.3129283
 1.4342941-0.6378252-1.6057577
 0.6456513 0.2481384-1.1617556
 
 ### rounding
 write.fwf(as.data.frame(round(myMat, 6)), file = , width = rep(9, 
 ncol(myMat)), sep = , colnames = FALSE)
-0.646486-0.628971-0.312928
 1.434294-0.637825-1.605758
 0.645651 0.248138-1.161756


With this approach I don't think you can get rid of the space between positive 
numbers because there should be place for a minus sign for negative values. If 
that's what you want


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of jim holtman
 Sent: 11. april 2014 22:39
 To: Doran, Harold
 Cc: r-help@r-project.org
 Subject: Re: [R] Save file as Fixed Width using sprintf()
 
 Try this.  It creates a 'list' that are the parameters for sprintf.  It
 writes out the file that I attach as the dump:
 
 ### Create a sample data matrix
 myMat - matrix(rnorm(9), 3,3)
 
 # create the format required -- make sure it is wide enough
 # for 'fixed' width
 xx - paste(rep(%8.2f, ncol(myMat)), collapse = '')
 # create a list for 'do.call(sprintf'
 callList - vector('list', ncol(myMat) + 1)
 callList[[1]] - xx  # store in the format
 
 # add the columns to the list
 for (i in seq(ncol(myMat))) callList[[i + 1L]] - myMat[, i]
 callList  # print it out
 
 result - do.call(sprintf, callList)
 
 # write out the data to a file
 writeLines(result, '/temp/file.txt')
 
 
 Here is what is in the file:
 
-0.390.45   -0.44
-0.82   -0.68   -0.43
 2.05   -0.850.61
 
 
 
 Jim Holtman
 Data Munger Guru
 
 What is the problem that you are trying to solve?
 Tell me what you want to do, not how you want to do it.
 
 
 On Fri, Apr 11, 2014 at 2:48 PM, Doran, Harold hdo...@air.org wrote:
 
  I have working code to write a file out as fwf as shown below. I have one
  question to try and automate this I cannot get to work.
 
  I am generating thousands of data files for a simulation to be run outside
  of R and each file varies in its dimensions. So I am trying to write code
  that can write the fwf based on the dimensions of each file generated as
  shown below. I have commented this code with an example to show
 where I am
  stuck.
 
  ### Create a sample data matrix
  myMat - matrix(rnorm(9), 3,3)
 
  ### Create the vector of format strings to be equal to the length of the
  columns in myMat
  aa - rep('%4f', ncol(myMat))
  xx - paste(aa, sep='', collapse='')
 
  ### Now I could just do this below and it works
  (out - sprintf(xx, myMat[, 1], myMat[, 2], myMat[, 3]) )
  out - as.matrix(out) # convert to a character matrix
  dimnames(out) - list(rep('', nrow(out)), '') # blank row and column names
  noquote(out) ## sink this file to a directory
 
  But, the fact that the dimensions of my matrix vary at each iteration
  means I need to automate this part in the sprint().
 
  myMat[, 1], myMat[, 2], myMat[, 3])
 
  I think that's needed because something like the following does not work
 
  (out - sprintf(xx, myMat[, 1:3]) )
 
 
  So, I thought about trying smoething like this
  cols - paste(paste('myMat[, ', 1:ncol(myMat), sep=''), ']', sep='')
  cols - paste(cols, collapse=', ')
 
  But, this is a string with quotation marks, so I thought using cat() might
  work, but it does not
 
  (out - sprintf(xx, cat(cols) ) )
 
  Anyone have a suggestion for the right way to do this, this is getting
  messy.
 
  Thank
  Harold
 
  [[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
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 
   [[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 http://www.R-project.org/posting-
 guide.html
 and provide 

Re: [R] invalid multibyte string at 'b0C'

2014-04-12 Thread Milan Bouchet-Valat
Le vendredi 11 avril 2014 à 16:02 -0700, Fisher Dennis a écrit :
 R 3.0.2
 OS X Mavericks
 
 Colleagues
 
 I have a file that I converted from SAS (sas7bdat) to CSV (filename:
 ORIGINAL.csv).  I try to read it with read.csv and I receive the error
 message:
   Error in type.convert(data[[i]], as.is = as.is[i], dec = dec,
 na.strings = character(0L)) : 
 invalid multibyte string at 'b0C’
 The problem resolves if I delete a single character from each of lines
 2 and 4 of the file (filename: FIXED.csv)
 
 readLines can read both files without problem and displays the
 offending character as:
   \xb0
 which appears to be a degree sign.
 
 I also tried:
   read.csv(textConnection(readLines(“ORIGINAL.csv”)))
 and encountered the same error message.
 
 In the past, I have encountered the same problem with Greek symbols
 (e.g., mu) and other special characters.
 
 Short of editing the input file, is there a simple solution within R
 so that I can read the input data into a dataframe?
 One possible (but ugly) solution would be:
   TEMP- readLines(FILENAME)
   TEMP- gsub(offendingcharacter, replacementcharacter, TEMP)
 However, this would require that I find all possible offending
 characters and the corresponding replacements.
Well, if the conversion too did its job correctly, you should be able to
find out what's the encoding used by the file and import these
characters correctly instead of removing them. b0 would be the correct
degree character in ISO-8859-1. So try
read.csv(file, fileEncoding=ISO-8859-1)

 The files are available for inspection at:
   http://www.plessthan.com/FILES/ARCHIVE.zip
The link does not appear to work here.


Regards

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] operating website through R

2014-04-12 Thread Suzen, Mehmet
This looks not so elegant, while normally data provider must have a
nice accessing API, anyway,  for example you can do this:

 myAdd - 
 'http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=60north=50east=70south=-50params=0|3B42_V7plot_type=Area+Plotbyr=2014bmo=01bdy=31eyr=2014emo=01edy=31begin_date=1998%2F01%2F01end_date=2014%2F01%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7prod_id=3B42_dailyaction=ASCII+Output'

 myData - read.table(myAdd, skip=5, header=T)

Will give you this:

 str(myData)
'data.frame':16441 obs. of  3 variables:
 $ Latitude : num  -50 -50 -50 -50 -50 -50 -50 -50 -50 -50 ...
 $ Longitude: num  60 60.2 60.5 60.8 61 ...
 $ AccRain  : num  0 0.42 0.39 0.42 0.66 1.23 2.31 2.37 3.72 3.63 ...

For choosing different parameters, for example in case of coordinates,
you just need to change the values in 'myAdd' parameters after
Giovanni_cgi.pl?, west, north, east, south. But you must be sure that
there is a data available with those parameters, no magical error
control here.

On 11 April 2014 17:45, eliza botto eliza_bo...@hotmail.com wrote:
 Dear Suzen,

 I couldn't understand. Could you please elaborate it with a small example?

 :(

 Thanks in advance.

 Eliza

 Date: Fri, 11 Apr 2014 17:31:18 +0200
 Subject: Re: [R] operating website through R
 From: msu...@gmail.com
 To: eliza_bo...@hotmail.com
 CC: r-help@r-project.org


 You just need to pass the parameters on Giovanni_cgi.pl with
 action=ASCII+Output

 On 11 April 2014 17:19, eliza botto eliza_bo...@hotmail.com wrote:
  Dear Users of R,
  I wanted to operate certain slots of this website
  (http://disc2.nascom.nasa.gov/Giovanni/tovas/TRMM_V7.3B42_daily.2.shtml)
  through R. I wanted to operate Latitude, longitude section, plot type, 
  begin
  and end year and ASCII Output Resolution. The filling of these slot will
  produce and output file with I want to D/L at a certain location in my PC.
  I have a matrix of 2 columns and 3000 rows which contain Latitude and
  Longitude information which i want to upload automatically in the slots of
  website. I tried to use certain web scarping techniques in R but to no use.
  Is there a way of doing it in R.
  thank you very much in advance,
  Eliza
 
 
  [[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
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] calling in inverted commas

2014-04-12 Thread arun
HI,
Thanks for the link.
I should have used ?sprintf().  BTW, I am not able to reproduce your results.

urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%params=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output
 
##


## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))
fileDestination - getwd()
fileNames - paste(precip, df2[,1], df2[,2], sep = _) 

fileNames - paste(fileNames, txt, sep = .) 

files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
 queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 
2])      download.file(queryUrl, files[i])
}



precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
+ sep = , check.names = FALSE, stringsAsFactors = FALSE) 

Error in read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,  
: 
  more columns than column names 


So, I checked the file precip_68.25_24.75.txt
Giovanni Error Message 
Giovanni Error Message Page
Error: instance configuration file  is not found. 
Error: product configuration file  is not found. 
Please send email to Help Desk: h...@daac.gs
fc.nasa.gov 
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit) 

A.K.


On Saturday, April 12, 2014 3:24 AM, Frede Aakmann Tøgersen fr...@vestas.com 
wrote:

Hi

Sigh I'm getting a headache seeing ugly formatted R code. Arun, your code is 
almost unreadable. Have a look at e.g. 
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Now to the substantial. Why not use the sprintf() function for formatting the 
url instead of the more involved approach using several gsub and regular 
expressions that not many people (including myself) easily understand.

## here is a small example using sprintf(), see ?sprintf
## %s is format specifier for string
exampleStr - west=%snorth=%seast=%ssouth=%s

sprintf(exampleStr, 1, 2, 3, 4)
##  [1] west=1north=2east=3south=4

## since % is used in format specification then if a literal % is needed in the 
string as here
## where you have e.g. %2F01% then escape those % with a %, i.e. % becomes %% 
in the string
## I have done that in urlPattern:
urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output

## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75)) 

fileDestination - c(C:/Temp)
fileNames - paste(precip, df2[,1], df2[,2], sep = _)
fileNames - paste(fileNames, txt, sep = .)
files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
    queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
    download.file(queryUrl, files[i])
}

## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
                     sep = , check.names = FALSE, stringsAsFactors = FALSE)

head(precip)


Here is another way using the url() function instead of download.file()

## Escaping the trouble with saving and reading files one can also do it this 
way
## having the dataframes in a named list
precipList - vector(list, nrow(df2))
names(precipList) - fileNames

for (i in 1:nrow(df2)){
    queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
    u - url(queryUrl, open = r)
    precipList[[i]] - read.table(u, skip = 4, header = TRUE, na.strings = 
-.9,
                     sep = , check.names = FALSE, stringsAsFactors = FALSE)
    close(u)
}

str(precipList)

Have a nice day.


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant Performance  Modeling

Technology  Service Solutions
T +45 9730 5135
M +45 2547 6050
fr...@vestas.com
http://www.vestas.com

Company reg. name: Vestas Wind Systems A/S
This e-mail is subject to our e-mail disclaimer statement.
Please refer to www.vestas.com/legal/notice
If you have received this e-mail in error please contact the sender. 


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of arun
 Sent: 12. april 2014 07:16
 To: r-help@r-project.org
 Subject: Re: [R] calling in inverted commas
 
 Hi,
 I noticed some special characters after sending.
 It should be:
 toreplace - gsub(.*\\.pl\\?(west\\=.*south=.*)\\params.*,\\1,Url1)
 end - gsub(.*south=.*(\\params.*),\\1,Url1)
 
 
 A.K.
 
 
 On Saturday, April 12, 2014 1:06 AM, 

Re: [R] calling in inverted commas

2014-04-12 Thread arun


HI,

Please ignore the previous message.  I copied your codes directly from the 
email.  For some reason, the urlPattern - ... showed some special characters.  
I manually fixed it and now it is working.


urlPattern1-(http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0%%7C3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7prod_id=3B42_dailyaction=ASCII+Output;)
 

fileDestination - getwd() 

fileNames - paste(precip, df2[,1], df2[,2], sep = _)
 fileNames - paste(fileNames, txt, sep = .)
 files - file.path(fileDestination, fileNames) 
for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern1, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
download.file(queryUrl, files[i])
}
 ## import data in first file 
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
sep = , check.names = FALSE, stringsAsFactors = FALSE) 
head(precip,2)
 #  Time(year:month:day) AccRain
 #1   1998:01:01   0
 #2   1998:01:02   0 

A.K.



On , arun smartpink...@yahoo.com wrote:
HI,
Thanks for the link.
I should have used ?sprintf().  BTW, I am not able to reproduce your results.

urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%params=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output
 
##


## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))
fileDestination - getwd()
fileNames - paste(precip, df2[,1], df2[,2], sep = _) 

fileNames - paste(fileNames, txt, sep = .) 

files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
 queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 
2])      download.file(queryUrl, files[i])
}



precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
+                     sep = , check.names = FALSE, stringsAsFactors = FALSE) 

Error in read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,  
: 
  more columns than column names 


So, I checked the file precip_68.25_24.75.txt
Giovanni Error Message 
Giovanni Error Message Page
Error: instance configuration file  is not found. 
Error: product configuration file  is not found. 
Please send email to Help Desk: h...@daac.gs
fc.nasa.gov 
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit) 

A.K.



On Saturday, April 12, 2014 3:24 AM, Frede Aakmann Tøgersen fr...@vestas.com 
wrote:

Hi

Sigh I'm getting a headache seeing ugly formatted R code. Arun, your code is 
almost unreadable. Have a look at e.g. 
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Now to the substantial. Why not use the sprintf() function for formatting the 
url instead of the more involved approach using several gsub and regular 
expressions that not many people (including myself) easily understand.

## here is a small example using sprintf(), see ?sprintf
## %s is format specifier for string
exampleStr - west=%snorth=%seast=%ssouth=%s

sprintf(exampleStr, 1, 2, 3, 4)
##  [1] west=1north=2east=3south=4

## since % is used in format specification then if a literal % is needed in the 
string as here
## where you have e.g. %2F01% then escape those % with a %, i.e. % becomes %% 
in the string
## I have done that in urlPattern:
urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output

## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75)) 

fileDestination - c(C:/Temp)
fileNames - paste(precip, df2[,1], df2[,2], sep = _)
fileNames - paste(fileNames, txt, sep = .)
files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
    queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
    download.file(queryUrl, files[i])
}

## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
                     sep = , check.names = FALSE, stringsAsFactors = FALSE)

head(precip)


Here is another way using the url() function instead of download.file()

## Escaping the trouble with saving and reading files one can also do it this 
way
## having the dataframes in a named list
precipList - vector(list, nrow(df2))

Re: [R] calling in inverted commas

2014-04-12 Thread Frede Aakmann Tøgersen
Hi Arun

It seems to be an error on the server side and not on the client.

The error on the server results in the client receiving a string giving the 
type of error on the server. And this doesn't work with read.table of course.

So if one wants to query for thousands of point one really needs to do error 
catching using try () or tryCatching ().

I shall check when I get close to my R.

Actually, if the thousands of points is on regular grid ( 0.25 degree 
resolution) within a confined region then one could just query for that region 
instead of doing the loop. Eliza should know.

Br. Frede

Sendt fra Samsung mobil


 Oprindelig meddelelse 
Fra: arun
Dato:12/04/2014 12.31 (GMT+01:00)
Til: Frede Aakmann Tøgersen
Cc: Eliza Botto ,R. Help
Emne: Re: [R] calling in inverted commas

HI,
Thanks for the link.
I should have used ?sprintf().  BTW, I am not able to reproduce your results.

urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%params=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output
##


## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))
fileDestination - getwd()
fileNames - paste(precip, df2[,1], df2[,2], sep = _)

fileNames - paste(fileNames, txt, sep = .)

files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
 queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 
2])  download.file(queryUrl, files[i])
}



precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
+ sep = , check.names = FALSE, stringsAsFactors = FALSE)

Error in read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,  
:
  more columns than column names


So, I checked the file precip_68.25_24.75.txt
Giovanni Error Message
Giovanni Error Message Page
Error: instance configuration file  is not found.
Error: product configuration file  is not found.
Please send email to Help Desk: h...@daac.gs
fc.nasa.gov
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

A.K.


On Saturday, April 12, 2014 3:24 AM, Frede Aakmann Tøgersen fr...@vestas.com 
wrote:

Hi

Sigh I'm getting a headache seeing ugly formatted R code. Arun, your code is 
almost unreadable. Have a look at e.g. 
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Now to the substantial. Why not use the sprintf() function for formatting the 
url instead of the more involved approach using several gsub and regular 
expressions that not many people (including myself) easily understand.

## here is a small example using sprintf(), see ?sprintf
## %s is format specifier for string
exampleStr - west=%snorth=%seast=%ssouth=%s

sprintf(exampleStr, 1, 2, 3, 4)
##  [1] west=1north=2east=3south=4

## since % is used in format specification then if a literal % is needed in the 
string as here
## where you have e.g. %2F01% then escape those % with a %, i.e. % becomes %% 
in the string
## I have done that in urlPattern:
urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output

## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))

fileDestination - c(C:/Temp)
fileNames - paste(precip, df2[,1], df2[,2], sep = _)
fileNames - paste(fileNames, txt, sep = .)
files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
download.file(queryUrl, files[i])
}

## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
 sep = , check.names = FALSE, stringsAsFactors = FALSE)

head(precip)


Here is another way using the url() function instead of download.file()

## Escaping the trouble with saving and reading files one can also do it this 
way
## having the dataframes in a named list
precipList - vector(list, nrow(df2))
names(precipList) - fileNames

for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
u - url(queryUrl, open = r)
precipList[[i]] - read.table(u, skip = 4, header = TRUE, na.strings = 
-.9,
 sep = , check.names = FALSE, stringsAsFactors = FALSE)
close(u)
}

str(precipList)

Have a nice day.


Yours sincerely / Med venlig hilsen


Frede Aakmann Tøgersen
Specialist, M.Sc., Ph.D.
Plant 

Re: [R] calling in inverted commas

2014-04-12 Thread Frede Aakmann Tøgersen
Oh, I see.

Actually I forgot to check whether if could be an advantage to use the 
URLencoding () function on queryUrl. I'll check later.

Br. Frede


Sendt fra Samsung mobil


 Oprindelig meddelelse 
Fra: arun
Dato:12/04/2014 12.45 (GMT+01:00)
Til: Frede Aakmann Tøgersen
Cc: Eliza Botto ,R. Help
Emne: Re: [R] calling in inverted commas



HI,

Please ignore the previous message.  I copied your codes directly from the 
email.  For some reason, the urlPattern - ... showed some special characters.  
I manually fixed it and now it is working.


urlPattern1-(http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0%%7C3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7prod_id=3B42_dailyaction=ASCII+Output;)

fileDestination - getwd()

fileNames - paste(precip, df2[,1], df2[,2], sep = _)
 fileNames - paste(fileNames, txt, sep = .)
 files - file.path(fileDestination, fileNames)
for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern1, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
download.file(queryUrl, files[i])
}
 ## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
sep = , check.names = FALSE, stringsAsFactors = FALSE)
head(precip,2)
 #  Time(year:month:day) AccRain
 #1   1998:01:01   0
 #2   1998:01:02   0

A.K.



On , arun smartpink...@yahoo.com wrote:
HI,
Thanks for the link.
I should have used ?sprintf().  BTW, I am not able to reproduce your results.

urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%params=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output
##


## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))
fileDestination - getwd()
fileNames - paste(precip, df2[,1], df2[,2], sep = _)

fileNames - paste(fileNames, txt, sep = .)

files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
 queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 
2])  download.file(queryUrl, files[i])
}



precip - read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,
+ sep = , check.names = FALSE, stringsAsFactors = FALSE)

Error in read.table(files[1], skip = 4, header = TRUE, na.strings = -.9,  
:
  more columns than column names


So, I checked the file precip_68.25_24.75.txt
Giovanni Error Message
Giovanni Error Message Page
Error: instance configuration file  is not found.
Error: product configuration file  is not found.
Please send email to Help Desk: h...@daac.gs
fc.nasa.gov
sessionInfo()
R version 3.0.2 (2013-09-25)
Platform: x86_64-unknown-linux-gnu (64-bit)

A.K.



On Saturday, April 12, 2014 3:24 AM, Frede Aakmann Tøgersen fr...@vestas.com 
wrote:

Hi

Sigh I'm getting a headache seeing ugly formatted R code. Arun, your code is 
almost unreadable. Have a look at e.g. 
http://yihui.name/en/2010/04/formatr-farewell-to-ugly-r-code/

Now to the substantial. Why not use the sprintf() function for formatting the 
url instead of the more involved approach using several gsub and regular 
expressions that not many people (including myself) easily understand.

## here is a small example using sprintf(), see ?sprintf
## %s is format specifier for string
exampleStr - west=%snorth=%seast=%ssouth=%s

sprintf(exampleStr, 1, 2, 3, 4)
##  [1] west=1north=2east=3south=4

## since % is used in format specification then if a literal % is needed in the 
string as here
## where you have e.g. %2F01% then escape those % with a %, i.e. % becomes %% 
in the string
## I have done that in urlPattern:
urlPattern - 
http://disc2.nascom.nasa.gov/daac-bin/Giovanni/tovas/Giovanni_cgi.pl?west=%snorth=%seast=%ssouth=%sparams=0|3B42_V7plot_type=Time+Plotbyr=1998bmo=01bdy=1eyr=2007emo=12edy=31begin_date=1998%%2F01%%2F01end_date=2014%%2F01%%2F31cbar=cdyncmin=cmax=yaxis=ydynymin=ymax=yint=ascres=0.25x0.25global_cfg=tovas.global.cfg.plinstance_id=TRMM_V7∏_id=3B42_dailyaction=ASCII+Output

## some coordinates
df2 - data.frame(Longitude = c(68.25, 68.75, 69.25), Latitude = c(24.75, 
25.25, 25.75))

fileDestination - c(C:/Temp)
fileNames - paste(precip, df2[,1], df2[,2], sep = _)
fileNames - paste(fileNames, txt, sep = .)
files - file.path(fileDestination, fileNames)

for (i in 1:nrow(df2)){
queryUrl - sprintf(urlPattern, df2[i, 1], df2[i, 2], df2[i, 1], df2[i, 2])
download.file(queryUrl, files[i])
}

## import data in first file
precip - read.table(files[1], skip = 4, header = TRUE, na.strings 

[R] Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Andrew Hoerner
Dear Folks--
I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
Census. I am trying to pare it down to a subset of rows that both (1) has
any one of a vector of NAICS economic sector codes, and (2) also has any
one of a vector of geographic ID codes.

Here is the code I am trying to use.

ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06, 33000US488,
31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
  any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
81), ]

I get back the following error:

Warning message:
In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
  longer object length is not a multiple of shorter object length

I see what R is doing.  Instead of comparing each element of the column
SECTOR to the row vector of codes, and returning a logical vector of the
length of SECTOR with rows marked as TRUE that match any of the codes, it
is lining my code list up with SECTOR as a column vector and doing
element-by-element testing, and then recycling the code list over three
million rows. But I am not sure how to make it do what I want -- test the
sector code in each row against the vector of code I am looking for. I
would be grateful if anyone could suggest an alternative that would achieve
my ends.

Oh, and I would add, if there is a way of correctly using doing this with
the extract function [], I would like to know what it is. If not, I guess
I'd like to know that too.

Sincerely, Andrew Hoerner

-- 
J. Andrew Hoerner
Director, Sustainable Economics Program
Redefining Progress
(510) 507-4820

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Sarah Goslee
You need %in% instead.

This is untested, but something like this should work:


ECwork  -  EC07_A1[ EC07_A1$GEO_ID %in% c(01000US, 04000US06, 33000US488,
31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
  EC07_A1$SECTOR %in% c(32, 33, 42, 44, 45, 51, 54, 61, 71,
81), ]

(Note that your original code snippet had a shortage of ) and didn't
specify the data frame from which to take the columns.)

Sarah

On Sat, Apr 12, 2014 at 8:36 AM, Andrew Hoerner ahoer...@rprogress.org wrote:
 Dear Folks--
 I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
 Census. I am trying to pare it down to a subset of rows that both (1) has
 any one of a vector of NAICS economic sector codes, and (2) also has any
 one of a vector of geographic ID codes.

 Here is the code I am trying to use.

 ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06, 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
   any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
 81), ]

 I get back the following error:

 Warning message:
 In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
   longer object length is not a multiple of shorter object length

 I see what R is doing.  Instead of comparing each element of the column
 SECTOR to the row vector of codes, and returning a logical vector of the
 length of SECTOR with rows marked as TRUE that match any of the codes, it
 is lining my code list up with SECTOR as a column vector and doing
 element-by-element testing, and then recycling the code list over three
 million rows. But I am not sure how to make it do what I want -- test the
 sector code in each row against the vector of code I am looking for. I
 would be grateful if anyone could suggest an alternative that would achieve
 my ends.

 Oh, and I would add, if there is a way of correctly using doing this with
 the extract function [], I would like to know what it is. If not, I guess
 I'd like to know that too.

 Sincerely, Andrew Hoerner

 --
 J. Andrew Hoerner
 Director, Sustainable Economics Program
 Redefining Progress
 (510) 507-4820

-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R, RStudio, and a server for my iPad.

2014-04-12 Thread Frans Marcelissen
Running rstudio (server) on an ipad.
I do'nt have an ipad anymore, but some years ago I noticed that rstudio
(server) worked fine on an ipad of you have a separate keyboard. It does
not work with the virtual keyboard. The same is true with android tablets.
Frans


2014-04-12 3:38 GMT+02:00 Roy Mendelssohn roy.mendelss...@noaa.gov:

 GIYF - Google VPN and iPad.

 -Roy

 On Apr 11, 2014, at 6:34 PM, John Sorkin jsor...@grecc.umaryland.edu
 wrote:

  David,
  Thank you for your assistance.
  I have, in fact been able to get things to work, at least when my iPad
 is on my local network. I had to do the following:
  (1) install Linux (I used linux Mint) on a computer on my LAN
  (2) install R on the linux box (accomplished using the Mint package
 manager)
  (3) install Rstudio and RStudio server on the linux box (accomplished
 using the Mint package manager)
  (4) obtain the linux computer's internal IP address (obtained using
 ifconfig command entered at a terminal). The internal IP address was
 192.168.0.101
  (5) use a browser on my iPad (I used google chrome, I believe firefox
 would also work) to connect to the linux box, requesting a connection using
 port 8787
  In the brower I entered http://192.168.0.101:8787
  This works like a charm; I can now control RStudio, which runs on the
 Linux box, by typing on my iPad. I thus gain access to RStudio on my iPad,
 RStudio works exactly as if it were running directly on my iPad, hooray!
 
  My remaining problem is to determine how I can gain access to the linux
 box from outside my LAN. I know the IP address of my cable router
 xx.xx.xx.xx (forgive me I am not listing my external IP address for
 security reasons), but I don't know how I can address the linux box from
 outside my LAN. Clearly I can't use 192.168.0.101 as it is an internal IP
 address, and I can't use the external IP address, xx.xx.xx.xx as it is the
 address of my cable box, not the address of the Linux box behind the cable
 modem. If I can figure how to address the linux box from outside my LAN my
 problem will be solved! If anyone can help me with this last problem I
 would be grateful. I know it is not strictly an R question, but in my case
 it is related to running R, at least on my iPad.
  John
 
 
 
 
  John David Sorkin M.D., Ph.D.
  Professor of Medicine
  Chief, Biostatistics and Informatics
  University of Maryland School of Medicine Division of Gerontology and
 Geriatric Medicine
  Baltimore VA Medical Center
  10 North Greene Street
  GRECC (BT/18/GR)
  Baltimore, MD 21201-1524
  (Phone) 410-605-7119
  (Fax) 410-605-7913 (Please call phone number above prior to faxing)
  David Winsemius dwinsem...@comcast.net 4/11/2014 9:06 PM 
 
  On Apr 11, 2014, at 2:00 PM, John Sorkin wrote:
 
  I bemoan the fact that I can not run R or Rstudio on my iPad. A
 possible work around would be to set up a server (probably under Linux),
 and get the server to present a web page that to would allow me to run R on
 the server.
 
 
  I fear that the response so far has been focussing on RStudio when the
 desire at its minimum was to run interactive R session on an iPad. Why not
 use an SSH client to connect to a machine that recognizes the security keys?
 
 
 https://itunes.apple.com/us/app/server-auditor-ssh-client/id549039908?mt=8
 
  I think RServe could be the server end, but I do not know how graphics
 devices would be handled. Maybe just create pdfs on the server? Is there a
 sendfile function that an SSH client could receive and allow the iPad user
 to open? I think the stats-rosuda-devel mailing list might be the place to
 find experienced users of such techniques.
 
  --
  David.
 
 
  I have searched the web for a clear, simple answer on how to do this
 but can not find one. There are answers, but not for someone who has not
 built a Linux server. Can someone provide either a reference to, or a short
 explanation of how I can build the server, get R or RStudio to run on it,
 and get the server and its R or RStudio program available to me on my iPad?
 I can probably find guidance on how to build an Apache server under Linux.
  Thank you,
  John
 
 
 
 
  John David Sorkin M.D., Ph.D.
  Professor of Medicine
  Chief, Biostatistics and Informatics
  University of Maryland School of Medicine Division of Gerontology and
 Geriatric Medicine
  Baltimore VA Medical Center
  10 North Greene Street
  GRECC (BT/18/GR)
  Baltimore, MD 21201-1524
  (Phone) 410-605-7119
  (Fax) 410-605-7913 (Please call phone number above prior to faxing)
 
  Confidentiality Statement:
  This email message, including any attachments, is for the sole use of
 the intended recipient(s) and may contain confidential and privileged
 information.  Any unauthorized use, disclosure or distribution is
 prohibited.  If you are not the intended recipient, please contact the
 sender by reply email and destroy all copies of the original message.
  __
  R-help@r-project.org mailing list
  

[R] Change position in package rgl

2014-04-12 Thread Roland Rau
Dear all,

I am using package rgl and I want to change the position where I stand.
Maybe a small example might clarify what I am looking for:


# Begininng of explanatory example
library(rgl)
data(volcano)

# the example ?rgl.surface
y - 2 * volcano
x - 10 * (1:nrow(y))
z - 10 * (1:ncol(y))
ylim - range(y)
ylen - ylim[2] - ylim[1] + 1
colorlut - terrain.colors(ylen)
col - colorlut[ y-ylim[1]+1 ]

rgl.open()
rgl.surface(x, z, y, color=col, back=lines)
## now I have the nice volcano surface
## with rgl.viewpoint I can change the elevation
## and the angle from where I look at the rgl.surface
# example of ?rgl.viewpoint
start - proc.time()[3]
while ((i - 36*(proc.time()[3]-start))  360) {
  rgl.viewpoint(i,i/4);
}
# End of explanatory example

What I am looking for (in this example) would be a way for me to stand
on the crater of the volcano, looking in a specific direction. Is there
something like a function where I can specify my coordinates (x,y,z) and
angle and a zoom factor?

Thank you,
Roland

--
This mail has been sent through the MPI for Demographic ...{{dropped:2}}

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Change position in package rgl

2014-04-12 Thread Duncan Murdoch

On 12/04/2014, 11:19 AM, Roland Rau wrote:

Dear all,

I am using package rgl and I want to change the position where I stand.
Maybe a small example might clarify what I am looking for:


# Begininng of explanatory example
library(rgl)
data(volcano)

# the example ?rgl.surface
y - 2 * volcano
x - 10 * (1:nrow(y))
z - 10 * (1:ncol(y))
ylim - range(y)
ylen - ylim[2] - ylim[1] + 1
colorlut - terrain.colors(ylen)
col - colorlut[ y-ylim[1]+1 ]

rgl.open()
rgl.surface(x, z, y, color=col, back=lines)
## now I have the nice volcano surface
## with rgl.viewpoint I can change the elevation
## and the angle from where I look at the rgl.surface
# example of ?rgl.viewpoint
start - proc.time()[3]
while ((i - 36*(proc.time()[3]-start))  360) {
   rgl.viewpoint(i,i/4);
}
# End of explanatory example

What I am looking for (in this example) would be a way for me to stand
on the crater of the volcano, looking in a specific direction. Is there
something like a function where I can specify my coordinates (x,y,z) and
angle and a zoom factor?


I think you could hack something like that (see the description in 
?par3d of how rendering is accomplished), but there's currently no 
support for it, and it wouldn't be easy, as currently P and M in that 
description are read-only quantities computed indirectly.  So you'd have 
to essentially trick rgl into producing the P matrix corresponding to 
the viewing position you want.


I am currently working on some changes that might make this easier, but 
they likely aren't going to be released for several months.


Duncan Murdoch

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R, RStudio, and a server for my iPad.

2014-04-12 Thread John Sorkin
Grand,
Thank you. I have been able to use my iPad to connect to a server running 
RStudio server as described in an earlier email and can use the virtual 
keyboard, which works but is not convenient as one needs to go from keyboard 
screen to another. 
My current problem is that while I can get everything to work when my iPad is 
on my local network, I don't know how to access my server from outside my LAN. 
I know my server's private IP address I know my cable modem's external IP 
address, but I have no idea what IP address to enter in my iPad, when my iPad 
is outside my LAN trying to access my server.
John

 On Apr 12, 2014, at 11:46 AM, Frans Marcelissen 
 fransiepansiekever...@gmail.com fransiepansiekever...@gmail.com wrote:
 
 Running rstudio (server) on an ipad.
 I do'nt have an ipad anymore, but some years ago I noticed that rstudio 
 (server) worked fine on an ipad of you have a separate keyboard. It does not 
 work with the virtual keyboard. The same is true with android tablets.
 Frans
 
 
 2014-04-12 3:38 GMT+02:00 Roy Mendelssohn roy.mendelss...@noaa.gov:
 GIYF - Google VPN and iPad.
 
 -Roy
 
 On Apr 11, 2014, at 6:34 PM, John Sorkin jsor...@grecc.umaryland.edu 
 wrote:
 
  David,
  Thank you for your assistance.
  I have, in fact been able to get things to work, at least when my iPad is 
  on my local network. I had to do the following:
  (1) install Linux (I used linux Mint) on a computer on my LAN
  (2) install R on the linux box (accomplished using the Mint package 
  manager)
  (3) install Rstudio and RStudio server on the linux box (accomplished 
  using the Mint package manager)
  (4) obtain the linux computer's internal IP address (obtained using 
  ifconfig command entered at a terminal). The internal IP address was 
  192.168.0.101
  (5) use a browser on my iPad (I used google chrome, I believe firefox 
  would also work) to connect to the linux box, requesting a connection 
  using port 8787
  In the brower I entered http://192.168.0.101:8787
  This works like a charm; I can now control RStudio, which runs on the 
  Linux box, by typing on my iPad. I thus gain access to RStudio on my iPad, 
  RStudio works exactly as if it were running directly on my iPad, hooray!
 
  My remaining problem is to determine how I can gain access to the linux 
  box from outside my LAN. I know the IP address of my cable router 
  xx.xx.xx.xx (forgive me I am not listing my external IP address for 
  security reasons), but I don't know how I can address the linux box from 
  outside my LAN. Clearly I can't use 192.168.0.101 as it is an internal IP 
  address, and I can't use the external IP address, xx.xx.xx.xx as it is the 
  address of my cable box, not the address of the Linux box behind the cable 
  modem. If I can figure how to address the linux box from outside my LAN my 
  problem will be solved! If anyone can help me with this last problem I 
  would be grateful. I know it is not strictly an R question, but in my case 
  it is related to running R, at least on my iPad.
  John
 
 
 
 
  John David Sorkin M.D., Ph.D.
  Professor of Medicine
  Chief, Biostatistics and Informatics
  University of Maryland School of Medicine Division of Gerontology and 
  Geriatric Medicine
  Baltimore VA Medical Center
  10 North Greene Street
  GRECC (BT/18/GR)
  Baltimore, MD 21201-1524
  (Phone) 410-605-7119
  (Fax) 410-605-7913 (Please call phone number above prior to faxing)
  David Winsemius dwinsem...@comcast.net 4/11/2014 9:06 PM 
 
  On Apr 11, 2014, at 2:00 PM, John Sorkin wrote:
 
  I bemoan the fact that I can not run R or Rstudio on my iPad. A possible 
  work around would be to set up a server (probably under Linux), and get 
  the server to present a web page that to would allow me to run R on the 
  server.
 
 
  I fear that the response so far has been focussing on RStudio when the 
  desire at its minimum was to run interactive R session on an iPad. Why not 
  use an SSH client to connect to a machine that recognizes the security 
  keys?
 
  https://itunes.apple.com/us/app/server-auditor-ssh-client/id549039908?mt=8
 
  I think RServe could be the server end, but I do not know how graphics 
  devices would be handled. Maybe just create pdfs on the server? Is there a 
  sendfile function that an SSH client could receive and allow the iPad user 
  to open? I think the stats-rosuda-devel mailing list might be the place to 
  find experienced users of such techniques.
 
  --
  David.
 
 
  I have searched the web for a clear, simple answer on how to do this but 
  can not find one. There are answers, but not for someone who has not 
  built a Linux server. Can someone provide either a reference to, or a 
  short explanation of how I can build the server, get R or RStudio to run 
  on it, and get the server and its R or RStudio program available to me on 
  my iPad? I can probably find guidance on how to build an Apache server 
  under Linux.
  Thank you,
  John
 
 
 
 
  John David Sorkin M.D., Ph.D.
 

Re: [R] R, RStudio, and a server for my iPad.

2014-04-12 Thread Jeff Newmiller
That you cannot reach your home LAN from the Internet without learning 
something about networking is a good thing, since that offers some hope that 
the Russian Mafia can't use your computer to launch criminal activities against 
the rest of us, either.

Studying how to set up a VPN on your network router was a good recommendation 
that you have not acknowledged. However, that subject is networking, not R, and 
is definitely off topic here. 
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On April 12, 2014 10:37:46 AM PDT, John Sorkin jsor...@grecc.umaryland.edu 
wrote:
Grand,
Thank you. I have been able to use my iPad to connect to a server
running RStudio server as described in an earlier email and can use the
virtual keyboard, which works but is not convenient as one needs to go
from keyboard screen to another. 
My current problem is that while I can get everything to work when my
iPad is on my local network, I don't know how to access my server from
outside my LAN. I know my server's private IP address I know my cable
modem's external IP address, but I have no idea what IP address to
enter in my iPad, when my iPad is outside my LAN trying to access my
server.
John

 On Apr 12, 2014, at 11:46 AM, Frans Marcelissen
fransiepansiekever...@gmail.com fransiepansiekever...@gmail.com
wrote:
 
 Running rstudio (server) on an ipad.
 I do'nt have an ipad anymore, but some years ago I noticed that
rstudio (server) worked fine on an ipad of you have a separate
keyboard. It does not work with the virtual keyboard. The same is true
with android tablets.
 Frans
 
 
 2014-04-12 3:38 GMT+02:00 Roy Mendelssohn roy.mendelss...@noaa.gov:
 GIYF - Google VPN and iPad.
 
 -Roy
 
 On Apr 11, 2014, at 6:34 PM, John Sorkin
jsor...@grecc.umaryland.edu wrote:
 
  David,
  Thank you for your assistance.
  I have, in fact been able to get things to work, at least when my
iPad is on my local network. I had to do the following:
  (1) install Linux (I used linux Mint) on a computer on my LAN
  (2) install R on the linux box (accomplished using the Mint
package manager)
  (3) install Rstudio and RStudio server on the linux box
(accomplished using the Mint package manager)
  (4) obtain the linux computer's internal IP address (obtained
using ifconfig command entered at a terminal). The internal IP address
was 192.168.0.101
  (5) use a browser on my iPad (I used google chrome, I believe
firefox would also work) to connect to the linux box, requesting a
connection using port 8787
  In the brower I entered http://192.168.0.101:8787
  This works like a charm; I can now control RStudio, which runs on
the Linux box, by typing on my iPad. I thus gain access to RStudio on
my iPad, RStudio works exactly as if it were running directly on my
iPad, hooray!
 
  My remaining problem is to determine how I can gain access to the
linux box from outside my LAN. I know the IP address of my cable router
xx.xx.xx.xx (forgive me I am not listing my external IP address for
security reasons), but I don't know how I can address the linux box
from outside my LAN. Clearly I can't use 192.168.0.101 as it is an
internal IP address, and I can't use the external IP address,
xx.xx.xx.xx as it is the address of my cable box, not the address of
the Linux box behind the cable modem. If I can figure how to address
the linux box from outside my LAN my problem will be solved! If anyone
can help me with this last problem I would be grateful. I know it is
not strictly an R question, but in my case it is related to running R,
at least on my iPad.
  John
 
 
 
 
  John David Sorkin M.D., Ph.D.
  Professor of Medicine
  Chief, Biostatistics and Informatics
  University of Maryland School of Medicine Division of Gerontology
and Geriatric Medicine
  Baltimore VA Medical Center
  10 North Greene Street
  GRECC (BT/18/GR)
  Baltimore, MD 21201-1524
  (Phone) 410-605-7119
  (Fax) 410-605-7913 (Please call phone number above prior to
faxing)
  David Winsemius dwinsem...@comcast.net 4/11/2014 9:06 PM 
 
  On Apr 11, 2014, at 2:00 PM, John Sorkin wrote:
 
  I bemoan the fact that I can not run R or Rstudio on my iPad. A
possible work around would be to set up a server (probably under
Linux), and get the server to present a web page that to would allow me
to run R on the server.
 
 
  I fear that the response so far has been focussing on RStudio when
the desire at its minimum was to run interactive R session on an iPad.
Why not use an SSH client to connect to a machine that 

Re: [R] R, RStudio, and a server for my iPad.

2014-04-12 Thread Viechtbauer Wolfgang (STAT)
You will have to enter the external IP address and then use port forwarding.

Just google for that term (port forwarding) ... For example:

http://www.howtogeek.com/66214/how-to-forward-ports-on-your-router/
http://en.wikipedia.org/wiki/Port_forwarding

Best,
Wolfgang

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
John Sorkin [jsor...@grecc.umaryland.edu]
Sent: Saturday, April 12, 2014 7:37 PM
To: fransiepansiekever...@gmail.com
Cc: r-help@r-project.org
Subject: Re: [R] R, RStudio, and a server for my iPad.

Grand,
Thank you. I have been able to use my iPad to connect to a server running 
RStudio server as described in an earlier email and can use the virtual 
keyboard, which works but is not convenient as one needs to go from keyboard 
screen to another.
My current problem is that while I can get everything to work when my iPad is 
on my local network, I don't know how to access my server from outside my LAN. 
I know my server's private IP address I know my cable modem's external IP 
address, but I have no idea what IP address to enter in my iPad, when my iPad 
is outside my LAN trying to access my server.
John
__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Programing routine comp()

2014-04-12 Thread Endy BlackEndy
Dear R users.
I am trying to program the comp() routine in package survMisc.


I am reading the data below with d=read.table( C:\\. .
.,fill=TRUE,header=TRUE)
Then I load the packages 'survival' and 'survMisc', library(survival),
library(survMisc)
 and I run the commands
  s=survfit(Surv(d[,2], d[,3])~d[,1],
data=d)
  comp(s)

 and I am getting the error
   Error in get(t1, loc1) : object 'd[,
2]' not found
If instead I use the commands
s=survfit(Surv(T, Status)~Group,
data=d)
   comp(s)

routine comp()  runs perfectly. However when I am programing I can't see a
way to know
in advance the variable names in order to use them.
Can anybody  give me a suggestion?

 Thanks in advance
   Endy

NB. The data must be stacked in three (3) columns before red.
They are repeated in nine (9) columns for space saving.

Group T Status Group T Status Group T Status
1 2081 0 1 55 1 2 414 1
1 1602 0 1 1 1 2 2204 1
1 1496 0 1 107 1 2 1063 1
1 1462 0 1 110 1 2 481 1
1 1433 0 1 332 1 2 105 1
1 1377 0 2 2569 0 2 641 1
1 1330 0 2 2506 0 2 390 1
1 996 0 2 2409 0 2 288 1
1 226 0 2 2218 0 2 421 1
1 1199 0 2 1857 0 2 79 1
1  0 2 1829 0 2 748 1
1 530 0 2 1562 0 2 486 1
1 1182 0 2 1470 0 2 48 1
1 1167 0 2 1363 0 2 272 1
1 418 1 2 1030 0 2 1074 1
1 383 1 2 860 0 2 381 1
1 276 1 2 1258 0 2 10 1
1 104 1 2 2246 0 2 53 1
1 609 1 2 1870 0 2 80 1
1 172 1 2 1799 0 2 35 1
1 487 1 2 1709 0 2 248 1
1 662 1 2 1674 0 2 704 1
1 194 1 2 1568 0 2 211 1
1 230 1 2 1527 0 2 219 1
1 526 1 2 1324 0 2 606 1
1 122 1 2 957 0
1 129 1 2 932 0
1 74 1 2 847 0
1 122 1 2 848 0
1 86 1 2 1850 0
1 466 1 2 1843 0
1 192 1 2 1535 0
1 109 1 2 1447 0
1 55 1 2 1384 0

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] [R-pkgs] Rcpp11 3.1.0 is on CRAN.

2014-04-12 Thread Romain Francois
Hello, 

R version 3.1.0 was released yesterday, and as always is welcome with great 
pleasure. One
of the features that is of particular interest to me is the support for C++11. 
I would encourage you to read 
[Writing R 
Extensions](http://cran.r-project.org/doc/manuals/r-devel/R-exts.html#Using-C_002b_002b11-code)
to familiarize yourself with 
what this supports means and how to take advantage of it. C++11 is a major 
upgrade of the C++ standard, making C++ more expressive, more efficient, more
fun to use and teach. It almost feels like a new language if you embrace it 
fully. 
The standards committee has done a great job of maintaining compatibility, 
which means
that code written with older standard will still compile and work. 
However, with C++11 code you write today and tomorrow will not be the same as 
code 
you used to write with C++98. 

To get the best of what C++11 has to offer, I'm releasing Rcpp11 today. Rcpp11
is a complete redesign of Rcpp, focused on C++11. Rcpp11 is a header only 
C++ library, distributed as an R package on CRAN, that facilitates embedding 
C++ code in R packages. 

I'll try to keep this announcement short. More details will follow on dedicated 
channels. I will just highlight a few aspects of Rcpp11 that are high level 
enough for such an annoucement. 

Header Only
===

Rcpp11 is header only -- it consists only of a set of `.h` files. Rcpp11 has no
`.cpp` files, and no R functions. This eliminates many problems inherent to 
binary compatibility that Rcpp has been fighting with for years. 

The recommended way to use Rcpp11 is to have these lines in the `DESCRIPTION` 
file 
of your package: 

```
LinkingTo: Rcpp11
SystemRequirements: C++11
```

Modernized code base


Many features of the original Rcpp code base are the consequence of my 
learning C++ and the internal API of R. After a few years of experience, I can 
now admit that mistakes were made while designing it. Unfortunately for reasons
outside of my control, it is not possible to fix these mistakes under the 
umbrella
of the Rcpp package. 

Things are radically different for Rcpp11, which I will maintain. Over the past 
few months, I have considered many features of the code base and either decided
to abandon them or upgrade them to the level of expectation we should have for 
a 
modern R/C++ interface. 


API
---

Most of what is usually called the API has been retained. I do not guarantee
low level compatibililty, but there is conceptual compatibility. For example, 
Rcpp11 contains all the classes we would expect: `NumericVector`, `List`, ...

I'm not going into details about what the individual differences are. Instead I 
will start documenting how to use the API provided by Rcpp11. 


Attributes
--

Attributes is probably the best feature that has ever been contributed to Rcpp. 
It 
gives a mechanism for decorating C++ functions, parsing these decorations and 
generating
scaffolding code around them.  

This feature has not been retained in Rcpp11, but instead has been moved into a 
new package called [attributes](https://github.com/Rcpp11/attributes), 
which is being developed and will be released later. 

It is worth mentioning that code generated by Rcpp's `compileAttributes` 
function
should be compilable against Rcpp11. When attributes becomes available it will 
provide a more flexible approach, and provide facilities for package authors to
implement and use their own attributes.


Modules
---

Rcpp modules was not retained as part of Rcpp11. This was a hard decision, 
because
I invested a lot of time developing the original code behind Rcpp modules. 
However
modules have significant problems which make them hard to maintain. Modules are 
also very demanding on the compiler. 

However, I still believe that the promise of Rcpp modules -- exposing C++ 
classes 
at the R level -- is very worthwhile. My plan is to redesign it using a 
different 
approach, more oriented towards code generation, à la attributes. 


Time and Date classes
-

I decided to abandon the classes responsible to handling dates and times. 
Better 
classes might be introduced when I'm comfortable with the design. Design 
documents and pull requests are welcome. 


Further discussion
==

Please consider subscribing to the R and C++ mailing list that was created a 
few 
days ago: https://groups.google.com/forum/#!forum/r-and-cpp

The scope of the mailing list is broader, the intention is to discuss all 
things 
R and C++. Questions about Rcpp11, Rcpp or anything related to using C++ and R
are welcome. As of today, 37 participants are registered. Please consider 
replying to this annoucement email through the mailing list. 

Rcpp11 is developed through the Rcpp11 organisation on github. Feel free
to report issues and submit pull requests. https://github.com/Rcpp11/Rcpp11


Versioning
==

The pattern that has been decided for versions of Rcpp11 is to use 

[R] Fwd: Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Andrew Hoerner
Thanks Sarah! That worked!

And you are quite right about the absence of parentheses and EC07_A1$ 's.
I apologize for sending that code snip -- I am not quite sure how I managed
to do it, since I had already fixed those problems and changed the code in
order to get the error message I posted.

Apropos of nothing in particular, before I could successfully impliment
your fix, I also had to learn another new thing. When saving a CSV file
with write.table, if you use sep=,  (that's double-quote comma space
double-quote) R puts the space _inside_ the quotation marks around
character variables. I'm not sure I would call that a bug, but I bet more
people are surprised by it than expect it.

Again, many thanks!

Andrew


On Sat, Apr 12, 2014 at 6:04 AM, Sarah Goslee sarah.gos...@gmail.comwrote:

 You need %in% instead.

 This is untested, but something like this should work:


 ECwork  -  EC07_A1[ EC07_A1$GEO_ID %in% c(01000US, 04000US06,
 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
   EC07_A1$SECTOR %in% c(32, 33, 42, 44, 45, 51, 54, 61,
 71,
 81), ]

 (Note that your original code snippet had a shortage of ) and didn't
 specify the data frame from which to take the columns.)

 Sarah

 On Sat, Apr 12, 2014 at 8:36 AM, Andrew Hoerner ahoer...@rprogress.org
 wrote:
  Dear Folks--
  I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
  Census. I am trying to pare it down to a subset of rows that both (1) has
  any one of a vector of NAICS economic sector codes, and (2) also has any
  one of a vector of geographic ID codes.
 
  Here is the code I am trying to use.
 
  ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06,
 33000US488,
  31000US41860, 31400US4186036084 05000US06001, E6000US0600153000)
 
any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
  81), ]
 
  I get back the following error:
 
  Warning message:
  In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
longer object length is not a multiple of shorter object length
 
  I see what R is doing.  Instead of comparing each element of the column
  SECTOR to the row vector of codes, and returning a logical vector of the
  length of SECTOR with rows marked as TRUE that match any of the codes, it
  is lining my code list up with SECTOR as a column vector and doing
  element-by-element testing, and then recycling the code list over three
  million rows. But I am not sure how to make it do what I want -- test the
  sector code in each row against the vector of code I am looking for. I
  would be grateful if anyone could suggest an alternative that would
 achieve
  my ends.
 
  Oh, and I would add, if there is a way of correctly using doing this with
  the extract function [], I would like to know what it is. If not, I guess
  I'd like to know that too.
 
  Sincerely, Andrew Hoerner
 
  --
  J. Andrew Hoerner
  Director, Sustainable Economics Program
  Redefining Progress
  (510) 507-4820
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org




-- 
J. Andrew Hoerner
Director, Sustainable Economics Program
Redefining Progress
(510) 507-4820



-- 
J. Andrew Hoerner
Director, Sustainable Economics Program
Redefining Progress
(510) 507-4820

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Sarah Goslee
Hi Andrew,

On Apr 12, 2014, at 6:36 PM, Andrew Hoerner ahoer...@rprogress.org wrote:

 Thanks Sarah! That worked!
 
 And you are quite right about the absence of parentheses and EC07_A1$ 's.
 I apologize for sending that code snip -- I am not quite sure how I managed
 to do it, since I had already fixed those problems and changed the code in
 order to get the error message I posted.
 
 Apropos of nothing in particular, before I could successfully impliment
 your fix, I also had to learn another new thing. When saving a CSV file
 with write.table, if you use sep=,  (that's double-quote comma space
 double-quote) R puts the space _inside_ the quotation marks around
 character variables. I'm not sure I would call that a bug, but I bet more
 people are surprised by it than expect it.

It shouldn’t; that’s incorrect. Can you provide a reproducible example?

When I look at your code  my reply, I notice that the quote marks are wrong 
too; could that be the actual problem?

Sarah

 
 Again, many thanks!
 
 Andrew
 
 
 On Sat, Apr 12, 2014 at 6:04 AM, Sarah Goslee sarah.gos...@gmail.comwrote:
 
 You need %in% instead.
 
 This is untested, but something like this should work:
 
 
 ECwork  -  EC07_A1[ EC07_A1$GEO_ID %in% c(01000US, 04000US06,
 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
  EC07_A1$SECTOR %in% c(32, 33, 42, 44, 45, 51, 54, 61,
 71,
 81), ]
 
 (Note that your original code snippet had a shortage of ) and didn't
 specify the data frame from which to take the columns.)
 
 Sarah
 
 On Sat, Apr 12, 2014 at 8:36 AM, Andrew Hoerner ahoer...@rprogress.org
 wrote:
 Dear Folks--
 I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
 Census. I am trying to pare it down to a subset of rows that both (1) has
 any one of a vector of NAICS economic sector codes, and (2) also has any
 one of a vector of geographic ID codes.
 
 Here is the code I am trying to use.
 
 ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06,
 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000)
 
  any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
 81), ]
 
 I get back the following error:
 
 Warning message:
 In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
  longer object length is not a multiple of shorter object length
 
 I see what R is doing.  Instead of comparing each element of the column
 SECTOR to the row vector of codes, and returning a logical vector of the
 length of SECTOR with rows marked as TRUE that match any of the codes, it
 is lining my code list up with SECTOR as a column vector and doing
 element-by-element testing, and then recycling the code list over three
 million rows. But I am not sure how to make it do what I want -- test the
 sector code in each row against the vector of code I am looking for. I
 would be grateful if anyone could suggest an alternative that would
 achieve
 my ends.
 
 Oh, and I would add, if there is a way of correctly using doing this with
 the extract function [], I would like to know what it is. If not, I guess
 I'd like to know that too.
 
 Sincerely, Andrew Hoerner
 
 --
 J. Andrew Hoerner
 Director, Sustainable Economics Program
 Redefining Progress
 (510) 507-4820
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org
 

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Andrew Hoerner
Oops! Spoke too soon.

Your fix fixed the problem I was having before, but it turns out the test
is now accepting every line. So there is still some problem with the logic
or with my implimentation of it.

I thought I should produce a reproducible example without 3 million lines
of data. I made a version with only the geography information and test.
Here is the code I am now using, applied to a file with only the first 8
lines of my geo data in it:

First I read the data in and print it out:

GEOshort.DF - read.table(C:\\Users\\andrewH\\Documents\\Oakland Tech
Project\\GEO_short.csv,
  header = FALSE, sep = ,, quote = \,  dec = .,
skip=1, col.names=
  c(originalRow, GEO_ID, GEOGRAPHY), fill = TRUE,
colClasses=character)

Which yields:

 GEOshort.DF
  originalRowGEO_ID GEOGRAPHY
1   1   01000US United States
23115 04000US01   Alabama
35501 04000US02Alaska
47924 04000US04   Arizona
5   10571 04000US05  Arkansas
6   14342 04000US06California
7   17913 04000US08  Colorado
8   20442 04000US09   Connecticut


Then I try to select the rows that match my geo-codes:

GEOextract.DF  - GEOshort.DF[
  any(GEOshort.DF$GEO_ID %in% c(01000US, 04000US06, 33000US488,
31000US41860,
  31400US4186036084, 05000US06001,
E6000US0600153000)), ]

This produces:
 GEOextract.DF
  originalRowGEO_ID GEOGRAPHY
1   1   01000US United States
23115 04000US01   Alabama
35501 04000US02Alaska
47924 04000US04   Arizona
5   10571 04000US05  Arkansas
6   14342 04000US06California
7   17913 04000US08  Colorado
8   20442 04000US09   Connecticut


This is what I want it to produce:

 GEOextract.DF
  originalRowGEO_ID GEOGRAPHY
1   1   01000US United States
2   14342 04000US06California

Sorry about the confusion, and thanks again for your kind attention.

Peace  joy, Andrew

... But pattern-matching doesn't equal comprehension.  --Peter
Watts


On Sat, Apr 12, 2014 at 6:04 AM, Sarah Goslee sarah.gos...@gmail.comwrote:

 You need %in% instead.

 This is untested, but something like this should work:


 ECwork  -  EC07_A1[ EC07_A1$GEO_ID %in% c(01000US, 04000US06,
 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
   EC07_A1$SECTOR %in% c(32, 33, 42, 44, 45, 51, 54, 61,
 71,
 81), ]

 (Note that your original code snippet had a shortage of ) and didn't
 specify the data frame from which to take the columns.)

 Sarah

 On Sat, Apr 12, 2014 at 8:36 AM, Andrew Hoerner ahoer...@rprogress.org
 wrote:
  Dear Folks--
  I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
  Census. I am trying to pare it down to a subset of rows that both (1) has
  any one of a vector of NAICS economic sector codes, and (2) also has any
  one of a vector of geographic ID codes.
 
  Here is the code I am trying to use.
 
  ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06,
 33000US488,
  31000US41860, 31400US4186036084 05000US06001, E6000US0600153000)
 
any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
  81), ]
 
  I get back the following error:
 
  Warning message:
  In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
longer object length is not a multiple of shorter object length
 
  I see what R is doing.  Instead of comparing each element of the column
  SECTOR to the row vector of codes, and returning a logical vector of the
  length of SECTOR with rows marked as TRUE that match any of the codes, it
  is lining my code list up with SECTOR as a column vector and doing
  element-by-element testing, and then recycling the code list over three
  million rows. But I am not sure how to make it do what I want -- test the
  sector code in each row against the vector of code I am looking for. I
  would be grateful if anyone could suggest an alternative that would
 achieve
  my ends.
 
  Oh, and I would add, if there is a way of correctly using doing this with
  the extract function [], I would like to know what it is. If not, I guess
  I'd like to know that too.
 
  Sincerely, Andrew Hoerner
 
  --
  J. Andrew Hoerner
  Director, Sustainable Economics Program
  Redefining Progress
  (510) 507-4820
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org




-- 
J. Andrew Hoerner
Director, Sustainable Economics Program
Redefining Progress
(510) 507-4820

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Pie charts using plotGooglemaps

2014-04-12 Thread drunkenphd
Hi, I am trying to add some pie charts in a list of coordinates. 
Please find attached data I am using 
Basically I am using this commands: 
 data-read.csv(file.choose(),header=T) coordinates(data) = ~ x + y
proj4string(data) = CRS(+proj=longlat +datum=WGS84) # colPalette defines
colors for plot mychart-segmentGoogleMaps(data,
zcol=c('City','Village'),mapTypeId='ROADMAP',
filename='myMap4.htm',colPalette=c('#E41A1C','#377EB8'),
strokeColor='black') 

But a map with legends shows up without any points or pie chart
Attached my csv https://www.dropbox.com/s/pkvq6xz0ynwok9r/sample.csv
Regards






--
View this message in context: 
http://r.789695.n4.nabble.com/Pie-charts-using-plotGooglemaps-tp4688678.html
Sent from the R help mailing list archive at Nabble.com.

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R 3.0.3, Windows 7: Problem installing XML package

2014-04-12 Thread Uwe Ligges



On 12.04.2014 22:39, Alpesh Pandya wrote:

Thank you for response Uwe. I tried multiple times by downloading the zip
file from many sources but still the same error. This is a major road block
for me in using R. Appreciate any help on this.


Please ask your local IT staff.

I get, using the same mirror:

 options(repos=c(CRAN=http://watson.nci.nih.gov/cran_mirror;))
 install.packages(XML, lib=d:/temp)
trying URL 
'http://watson.nci.nih.gov/cran_mirror/bin/windows/contrib/3.0/XML_3.98-1.1.zip'

Content type 'application/zip' length 4288136 bytes (4.1 Mb)
opened URL
downloaded 4.1 Mb

package ‘XML’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
d:\temp\RtmpqMqL8L\downloaded_packages



Best,
Uwe Ligges








On Fri, Apr 11, 2014 at 6:53 PM, Uwe Ligges lig...@statistik.tu-dortmund.de

wrote:



Works for me.

Best,
Uwe Ligges




On 11.04.2014 17:10, Alpesh Pandya wrote:


Using install.package('XML') command produces this error:

trying URL
'
http://watson.nci.nih.gov/cran_mirror/bin/windows/
contrib/3.0/XML_3.98-1.1.zip
'
Content type 'application/zip' length 4288136 bytes (4.1 Mb)
opened URL
downloaded 4.1 Mb

Error in read.dcf(file.path(pkgname, DESCRIPTION), c(Package,
Type)) :
cannot open the connection
In addition: Warning messages:
1: In download.file(url, destfile, method, mode = wb, ...) :
downloaded length 4276224 != reported length 4288136
2: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
3: In read.dcf(file.path(pkgname, DESCRIPTION), c(Package, Type)) :
cannot open compressed file 'XML/DESCRIPTION', probable reason 'No such
file or directory'


Upon receiving this error, I downloaded XML_3.98-1.1.zip directly from
cran
site. But this zip file is not a valid archive (cannot open using winzip).
Also trying to install using this downloaded file produces the following
error:

Installing package into 'C:/Users/APandya/Documents/R/win-library/3.0'
(as 'lib' is unspecified)
Warning in install.packages :
error 1 in extracting from zip file
Warning in install.packages :
cannot open compressed file 'XML/DESCRIPTION', probable reason 'No such
file or directory'
Error in install.packages : cannot open the connection

I  downloaded this zip file from multiple sources and tried to install
with
same result.







__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Pie charts using plotGooglemaps

2014-04-12 Thread Jim Lemon

On 04/13/2014 09:20 AM, drunkenphd wrote:

Hi, I am trying to add some pie charts in a list of coordinates.
Please find attached data I am using
Basically I am using this commands:
  data-read.csv(file.choose(),header=T) coordinates(data) = ~ x + y
proj4string(data) = CRS(+proj=longlat +datum=WGS84) # colPalette defines
colors for plot mychart-segmentGoogleMaps(data,
zcol=c('City','Village'),mapTypeId='ROADMAP',
filename='myMap4.htm',colPalette=c('#E41A1C','#377EB8'),
strokeColor='black')

But a map with legends shows up without any points or pie chart
Attached my csv https://www.dropbox.com/s/pkvq6xz0ynwok9r/sample.csv


Hi drunkenphd,
If you have the coordinates, you can use the floating.pie function in 
the plotrix package.


Jim

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Pie charts using plotGooglemaps

2014-04-12 Thread drunkenphd
Jim thx,
Can you please provide me an example how to use my csv data with plotrix
float.pie???



--
View this message in context: 
http://r.789695.n4.nabble.com/Pie-charts-using-plotGooglemaps-tp4688678p4688683.html
Sent from the R help mailing list archive at Nabble.com.

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Selecting rows from a DF where the value in a selected column matches any element of a vector.

2014-04-12 Thread Sarah Goslee
See inline.

On Apr 12, 2014, at 7:04 PM, Andrew Hoerner ahoer...@rprogress.org wrote:

 Oops! Spoke too soon.
 
 Your fix fixed the problem I was having before, but it turns out the test is 
 now accepting every line. So there is still some problem with the logic or 
 with my implimentation of it.
 
 I thought I should produce a reproducible example without 3 million lines of 
 data. I made a version with only the geography information and test. Here is 
 the code I am now using, applied to a file with only the first 8 lines of my 
 geo data in it:

Please use dput() to provide data, rather than copy  paste, since that’s not 
reproducible.


 
 First I read the data in and print it out:
 
 GEOshort.DF - read.table(C:\\Users\\andrewH\\Documents\\Oakland Tech 
 Project\\GEO_short.csv, 
   header = FALSE, sep = ,, quote = \,  dec = ., 
 skip=1, col.names=
   c(originalRow, GEO_ID, GEOGRAPHY), fill = TRUE, 
 colClasses=character)
 
 Which yields:
 
  GEOshort.DF
   originalRowGEO_ID GEOGRAPHY
 1   1   01000US United States
 23115 04000US01   Alabama
 35501 04000US02Alaska
 47924 04000US04   Arizona
 5   10571 04000US05  Arkansas
 6   14342 04000US06California
 7   17913 04000US08  Colorado
 8   20442 04000US09   Connecticut
 
 
 Then I try to select the rows that match my geo-codes:
 
 GEOextract.DF  - GEOshort.DF[
   any(GEOshort.DF$GEO_ID %in% c(01000US, 04000US06, 33000US488, 
 31000US41860, 
   31400US4186036084, 05000US06001, 
 E6000US0600153000)), ]

But that’s not what I suggested: if you use any(), then if there are any 
matches it will return TRUE and by expansion you’ll get all the rows. You need:

GEOextract.DF  - GEOshort.DF[
GEOshort.DF$GEO_ID %in% c(01000US, 04000US06, 33000US488, 31000US41860, 
  31400US4186036084, 05000US06001, 
E6000US0600153000), ]

You can check this yourself by running just the logical portion: compare

any(GEOshort.DF$GEO_ID %in% c(01000US, 04000US06, 33000US488, 
31000US41860, 
  31400US4186036084, 05000US06001, 
E6000US0600153000))
with

GEOshort.DF$GEO_ID %in% c(01000US, 04000US06, 33000US488, 31000US41860, 
  31400US4186036084, 05000US06001, 
“E6000US0600153000)

 
 ... But pattern-matching doesn't equal comprehension.  --Peter Watts

Happy to help a Peter Watts fan. 

Sarah


 
 
 On Sat, Apr 12, 2014 at 6:04 AM, Sarah Goslee sarah.gos...@gmail.com wrote:
 You need %in% instead.
 
 This is untested, but something like this should work:
 
 
 ECwork  -  EC07_A1[ EC07_A1$GEO_ID %in% c(01000US, 04000US06, 
 33000US488,
 31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
   EC07_A1$SECTOR %in% c(32, 33, 42, 44, 45, 51, 54, 61, 71,
 81), ]
 
 (Note that your original code snippet had a shortage of ) and didn't
 specify the data frame from which to take the columns.)
 
 Sarah
 
 On Sat, Apr 12, 2014 at 8:36 AM, Andrew Hoerner ahoer...@rprogress.org 
 wrote:
  Dear Folks--
  I have a file with 3 million-odd rows of data from the 2007 U.S. Economic
  Census. I am trying to pare it down to a subset of rows that both (1) has
  any one of a vector of NAICS economic sector codes, and (2) also has any
  one of a vector of geographic ID codes.
 
  Here is the code I am trying to use.
 
  ECwork  -  EC07_A1[ any(GEO_ID == c(01000US, 04000US06, 33000US488,
  31000US41860, 31400US4186036084 05000US06001, E6000US0600153000) 
any(SECTOR == c(32, 33, 42, 44, 45, 51, 54, 61, 71,
  81), ]
 
  I get back the following error:
 
  Warning message:
  In EC07_A1$SECTOR == c(32, 33, 42, 44, 45, 51, 54,  :
longer object length is not a multiple of shorter object length
 
  I see what R is doing.  Instead of comparing each element of the column
  SECTOR to the row vector of codes, and returning a logical vector of the
  length of SECTOR with rows marked as TRUE that match any of the codes, it
  is lining my code list up with SECTOR as a column vector and doing
  element-by-element testing, and then recycling the code list over three
  million rows. But I am not sure how to make it do what I want -- test the
  sector code in each row against the vector of code I am looking for. I
  would be grateful if anyone could suggest an alternative that would achieve
  my ends.
 
  Oh, and I would add, if there is a way of correctly using doing this with
  the extract function [], I would like to know what it is. If not, I guess
  I'd like to know that too.
 
  Sincerely, Andrew Hoerner
 
  --
  J. Andrew Hoerner
  Director, Sustainable Economics Program
  Redefining Progress
  (510) 507-4820
 
 --
 Sarah Goslee
 http://www.functionaldiversity.org
 
 
 
 -- 
 J. Andrew Hoerner
 Director, Sustainable Economics Program
 Redefining Progress
 (510) 507-4820

__
R-help@r-project.org mailing list

[R] Adding Nested Random Effects to MCMCglmm

2014-04-12 Thread Marian L. Firke
Dear R Experts, 

Does anyone have advice for how to nest random effects in the MCMCglmm package? 

Right now, I am running my models with Individual as a random effect; however, 
the 25 individuals in my study are birds taken from 13 different nests, so I 
feel that a more accurate model would nest the variable Individual (called RNR 
in my code) within the variable Nest ID. 

I am trying to run both univariate and bivariate mixed models using the 
MCMCglmm package. (My interest is in calculating repeatability estimates using 
the univariate models, and in partitioning out the within-individual and 
between-individual correlations using the bivariate models.) I am also trying 
to include a fixed effect (SMI) but am not sure that I am doing this correctly 
for either case. 



Example Univariate MM: 
Cort0.mcmc-MCMCglmm(CORT0_LOG10_Z~SMI_CEN, random=~indiv, family=gaussian, 
data=cort0.data,verbose=FALSE)

CORT0_LOG10_Z is the variable of interest (which has been measured repeatedly 
for each given individual) 
RNR is individual ID 
SMI_CEN is a fixed effect that varies both within and between individuals

Example piece of data frame: 

  RNR HPA CORT0_LOG10_Z  SMI_CEN  NEST_ID
1  AR04273   1   -3.29844317 1.236170087  3
2  AR04273   2   -0.51328002 0.122035902  3
3  AR04281   10.83631319 1.212914325  8


Example Bivariate MM: 
cort0_cort15.bivarC.mcmc-MCMCglmm(cbind(CORT0_std,CORT15_std)~(SMI_cen), 
random=~us(trait):RNR, rcov=~us(trait):units, family=c(gaussian,gaussian), 
prior=prior.bivar, nitt=130,thin=1000,burnin=30, 
data=cort0_cort15,verbose=FALSE)

CORT0_std and CORT15_std are the 2 variables of interest
RNR is individual ID 
SMI_cen is a fixed effect that varies both within and between individuals

Example piece of data frame: 
RNR  SMI  SMI_avg  SMI_dev  CORT0 CORT15  SMI_cen SMI_avg_cen   
CORT0_std   CORT15_std  NEST_ID
1  AR04273 18.03640 17.48987  0.546522102  0.460  4.590  1.236170087  
0.73332960 -3.80922656 -3.170123623  3
2  AR04273 16.94335 17.48987 -0.546522102  3.493 13.604  0.122035902  
0.73332960 -0.04862913 -0.480133012  3
3  AR04281 15.63367 15.86610 -0.232427804  4.875 13.507 -1.212914325 
-1.05393597  0.56974795 -0.497849822  8

I am basing my code off of the code supplied in the 2013 paper by Dingemanse 
and Dochtermann about applying linear mixed modelling to behavioral ecology. 

Does anyone have advice for how to nest RNR within Nest ID, as well as insight 
into whether I have coded the fixed effect SMI correctly? 


Many thanks, 
Marian

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How two have two legends on a chart with different groups?

2014-04-12 Thread jcrosbie
I'm trying to have two legends on a chart, with two sets of data with
subgroups. Currently ggplot is are merging the to sets of data together.

I would like to have the vertical lines in there own legend and not affect
the colour shading or show up in the type legend.

How would I go about doing this?

df - data.frame(val1=rnorm(300, 75, 10), val2=rnorm(300, 75,
10),type=rep(c(A, B, C),100))

cuts1 - data.frame(Stats=Stat A, vals=c(43, 70, 90))
cuts2 - data.frame(Stats=Stat B, vals=cuts2 - c(46, 79, 86))

cuts - rbind(cuts1,cuts2)

ggplot(df, aes(x=val1, y=val2, group=type)) +
geom_line(aes(colour=type))+
geom_point(aes(colour=type))+
geom_vline(data=cuts, 
 aes(xintercept=vals, 
 linetype=Stats,
 colour = Stats),
 show_guide = TRUE)
I got the idea of how to do this from: Add vline to existing plot and have
it appear in ggplot2 legend?



--
View this message in context: 
http://r.789695.n4.nabble.com/How-two-have-two-legends-on-a-chart-with-different-groups-tp4688666.html
Sent from the R help mailing list archive at Nabble.com.

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R 3.0.3, Windows 7: Problem installing XML package

2014-04-12 Thread Alpesh Pandya
Thank you for response Uwe. I tried multiple times by downloading the zip
file from many sources but still the same error. This is a major road block
for me in using R. Appreciate any help on this.


On Fri, Apr 11, 2014 at 6:53 PM, Uwe Ligges lig...@statistik.tu-dortmund.de
 wrote:

 Works for me.

 Best,
 Uwe Ligges




 On 11.04.2014 17:10, Alpesh Pandya wrote:

 Using install.package('XML') command produces this error:

 trying URL
 '
 http://watson.nci.nih.gov/cran_mirror/bin/windows/
 contrib/3.0/XML_3.98-1.1.zip
 '
 Content type 'application/zip' length 4288136 bytes (4.1 Mb)
 opened URL
 downloaded 4.1 Mb

 Error in read.dcf(file.path(pkgname, DESCRIPTION), c(Package,
 Type)) :
cannot open the connection
 In addition: Warning messages:
 1: In download.file(url, destfile, method, mode = wb, ...) :
downloaded length 4276224 != reported length 4288136
 2: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
 3: In read.dcf(file.path(pkgname, DESCRIPTION), c(Package, Type)) :
cannot open compressed file 'XML/DESCRIPTION', probable reason 'No such
 file or directory'


 Upon receiving this error, I downloaded XML_3.98-1.1.zip directly from
 cran
 site. But this zip file is not a valid archive (cannot open using winzip).
 Also trying to install using this downloaded file produces the following
 error:

 Installing package into 'C:/Users/APandya/Documents/R/win-library/3.0'
 (as 'lib' is unspecified)
 Warning in install.packages :
error 1 in extracting from zip file
 Warning in install.packages :
cannot open compressed file 'XML/DESCRIPTION', probable reason 'No such
 file or directory'
 Error in install.packages : cannot open the connection

 I  downloaded this zip file from multiple sources and tried to install
 with
 same result.




-- 
Thanks and Regards
Alpesh

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] [R-pkgs] frailtypack package 2.6

2014-04-12 Thread Rondeau Virginie
Dear R users,

the frailtypack package, for the analysis of correlated survival data, 
has been updated on CRAN.

The major changes in version 2.6 are:

* Fit now a multivariate gaussian frailty model (two types of recurrent 
events and a terminal event). For instance here is a model that fits a 
weibull multivariate gaussian frailty model with different adjustments:

* modMultiv.weib - 
multivPenal(Surv(TIMEGAP,INDICREC)~cluster(PATIENT)+v1+v2+ 
event2(INDICMETA)+terminal(INDICDEATH),formula.Event2=~v1+v2+v3, 
formula.terminalEvent=~v1,data=dataMultiv,hazard=Weibull) *

* New dynamic tool of prediction probabilities in Cox models, standard 
shared frailty models or joint frailty models.

* Concordance measures for clustered data.

* initialization of regression coefficients, variance of the random 
effects, and alpha now available in joint frailty models. Moreover, with 
'Alpha=none', frailtyPenal can fit a joint model with a fixed alpha (=1).

* Interval-censored frailty models.

Best regards,

Virginie Rondeau, Alexandre Laurent




[[alternative HTML version deleted]]

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Reading output of a GLMM run in R

2014-04-12 Thread ruth harries
Hi, I am a complete novice and dummy when it comes to statistics so I apologise 
in advance... I have been asked to report the results of my GLMMs (I ran two) 
in a table. This table must state: effect, standard error, test statistic, and 
P value, for all fixed effects. Unfortunately I am struggling to read my 
output. The out put is as follows, if anyone would be kind enough to help I 
would be very grateful and will know for future reference which bit equates to 
what (also I have been told my degrees of freedom are different for both the 
tests, could someone explain why this is?). GLMM 1-run for predictors of step 
length. Response variable = step length. fixed effects = depth and direction 
threshold. random factor = individual Models: m2: step ~ (1 | ind) m1: step ~ 
Depth * threshold + (1 | ind) Df AIC BIC logLik deviance Chisq Chi Df 
Pr(Chisq) m2 3 373235 373259 -186615 373229 m1 8 373225 373290 -186605 373209 
19.767 5 0.001382 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 
0.1 ‘ ’ 1 GLMM 2 -run to investigate potential predictors of PDBA. response 
variables = depth and step length. fixed effect = direction threshold. random 
factor = Individual Models: m3: PDBA ~ Depth + (1 | ind) + thresholdepth m2: 
PDBA ~ step * threshold + Depth * threshold + (1 | ind) Df AIC BIC logLik 
deviance Chisq Chi Df Pr(Chisq) m3 6 -48205 -48157 24109 -48217 m2 11 -48430 
-48341 24226 -48452 235.1 5  2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 
0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Models: m4: PDBA ~ step + (1 | ind) + 
step:threshold m2: PDBA ~ step * threshold + Depth * threshold + (1 | ind) Df 
AIC BIC logLik deviance Chisq Chi Df Pr(Chisq) m4 6 -48206 -48158 24109 -48218 
m2 11 -48430 -48341 24226 -48452 233.81 5  2.2e-16 *** --- Signif. codes: 0 
‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] R 3.0.3, Windows 7: Problem installing XML package

2014-04-12 Thread Alpesh Pandya
@Uwe I tried the same steps from office as well as home network with same
results. Are you using windows 7 with R 3.0.3?

I have seen same question being asked by others without any resolution. Is
anything special about XML package? I am OK use older version of package
but in archives there are no zip files (only gz files). Is windows platform
not recommended for R?


On Sat, Apr 12, 2014 at 7:22 PM, Uwe Ligges lig...@statistik.tu-dortmund.de
 wrote:



 On 12.04.2014 22:39, Alpesh Pandya wrote:

 Thank you for response Uwe. I tried multiple times by downloading the zip
 file from many sources but still the same error. This is a major road
 block
 for me in using R. Appreciate any help on this.


 Please ask your local IT staff.

 I get, using the same mirror:

  options(repos=c(CRAN=http://watson.nci.nih.gov/cran_mirror;))
  install.packages(XML, lib=d:/temp)

 trying URL 'http://watson.nci.nih.gov/cran_mirror/bin/windows/
 contrib/3.0/XML_3.98-1.1.zip'
 Content type 'application/zip' length 4288136 bytes (4.1 Mb)
 opened URL
 downloaded 4.1 Mb

 package 'XML' successfully unpacked and MD5 sums checked

 The downloaded binary packages are in
 d:\temp\RtmpqMqL8L\downloaded_packages



 Best,
 Uwe Ligges








 On Fri, Apr 11, 2014 at 6:53 PM, Uwe Ligges 
 lig...@statistik.tu-dortmund.de

 wrote:


  Works for me.

 Best,
 Uwe Ligges




 On 11.04.2014 17:10, Alpesh Pandya wrote:

  Using install.package('XML') command produces this error:

 trying URL
 '
 http://watson.nci.nih.gov/cran_mirror/bin/windows/
 contrib/3.0/XML_3.98-1.1.zip
 '
 Content type 'application/zip' length 4288136 bytes (4.1 Mb)
 opened URL
 downloaded 4.1 Mb

 Error in read.dcf(file.path(pkgname, DESCRIPTION), c(Package,
 Type)) :
 cannot open the connection
 In addition: Warning messages:
 1: In download.file(url, destfile, method, mode = wb, ...) :
 downloaded length 4276224 != reported length 4288136
 2: In unzip(zipname, exdir = dest) : error 1 in extracting from zip file
 3: In read.dcf(file.path(pkgname, DESCRIPTION), c(Package, Type))
 :
 cannot open compressed file 'XML/DESCRIPTION', probable reason 'No
 such
 file or directory'


 Upon receiving this error, I downloaded XML_3.98-1.1.zip directly from
 cran
 site. But this zip file is not a valid archive (cannot open using
 winzip).
 Also trying to install using this downloaded file produces the following
 error:

 Installing package into 'C:/Users/APandya/Documents/R/win-library/3.0'
 (as 'lib' is unspecified)
 Warning in install.packages :
 error 1 in extracting from zip file
 Warning in install.packages :
 cannot open compressed file 'XML/DESCRIPTION', probable reason 'No
 such
 file or directory'
 Error in install.packages : cannot open the connection

 I  downloaded this zip file from multiple sources and tried to install
 with
 same result.







-- 
Thanks and Regards
Alpesh

[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] FW: Reading output of a GLMM run in R

2014-04-12 Thread ruth harries





Hi, I am a complete novice and dummy when it comes to statistics so I apologise 
in advance... I have been asked to report the results of my GLMMs (I ran two) 
in a table. This table must state: effect, standard error, test statistic, and 
P value, for all fixed effects. Unfortunately I am struggling to read my 
output. The out put is as follows, if anyone would be kind enough to help I 
would be very grateful and will know for future reference which bit equates to 
what (also I have been told my degrees of freedom are different for both the 
tests, could someone explain why this is?). GLMM 1-run for predictors of step 
length. Response variable = step length. fixed effects = depth and direction 
threshold. random factor = individual Models: m2: step ~ (1 | ind) m1: step ~ 
Depth * threshold + (1 | ind) Df AIC BIC logLik deviance Chisq Chi Df 
Pr(Chisq) m2 3 373235 373259 -186615 373229 m1 8 373225 373290 -186605 373209 
19.767 5 0.001382 ** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 
0.1 ‘ ’ 1 GLMM 2 -run to investigate potential predictors of PDBA. response 
variables = depth and step length. fixed effect = direction threshold. random 
factor = Individual Models: m3: PDBA ~ Depth + (1 | ind) + thresholdepth m2: 
PDBA ~ step * threshold + Depth * threshold + (1 | ind) Df AIC BIC logLik 
deviance Chisq Chi Df Pr(Chisq) m3 6 -48205 -48157 24109 -48217 m2 11 -48430 
-48341 24226 -48452 235.1 5  2.2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 
0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Models: m4: PDBA ~ step + (1 | ind) + 
step:threshold m2: PDBA ~ step * threshold + Depth * threshold + (1 | ind) Df 
AIC BIC logLik deviance Chisq Chi Df Pr(Chisq) m4 6 -48206 -48158 24109 -48218 
m2 11 -48430 -48341 24226 -48452 233.81 5  2.2e-16 *** --- Signif. codes: 0 
‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 
[[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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.