Re: [R] Reading CSV file

2013-04-19 Thread Bretschneider SIG-R
Dear Gafar Matanmi Oyeyemi,


Re:

 I am trying to read a csv file using the code;
 contol - read.csv(RBS.csv)
 This is the error message I got;
 Error in file(file, r) : unable to open connection
 In addition: Warning message:
 In file(file, r) :
 cannot open file 'RBS.csv', reason 'No such file or directory'
 




I always use file.choose() to find the exact path name, e.g.
contol - read.csv(file.choose())
After having found the path name, you can put it in the R source text for 
future use (provided it remains the same of course).
Best wishes,


Franklin Bretschneider



--
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] A categorized list of R functions

2013-04-08 Thread Bretschneider SIG-R
Dear Rees Morrison,


Re:

(...)
 
 What additional code would create a table output, with the function name in 
 the left column, sorted alphabetically within a pattern, and the pattern of 
 the function in the column to the right.  Users could then sort by those 
 patterns, rename some to suit themselves, etc.
(...)


The version below creates a tab-delimited table with 3 columns: seach string, 
package name and function name. 
Can be imported e.g. in Excel. Maybe not elegant, but seems to work (however: 
test it!).
Column order can be changed by changing the printing order of newhits[ ,1]  ,2 
and ,3.

In addition, Liviu Andronic's suggestion to use the package sos (strange 
name, but good tip) seems also interesting.

Best wishes,


Franklin Bretschneider
--
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

- - - - - - - - - - - - - - - - - 

#  categorize functions 2.R
#  Franklin Bretschneider
#  after R-help, R. Michael Weylandt
#  08-04-2013
#  this version produces a tab-delimited text file with 
#  the columns: (search) pattern; (in which) package and function (name).
#  ==
allfuncs = unlist(sapply(search(), ls)) 
n = length(allfuncs)
allnames = names(allfuncs)
package.names = substr(allnames, start=9, stop=nchar(allnames))
allfuncs = cbind(package.names, allfuncs)
#  which patterns to search: can be customized
patterns = c(print, plot, axes, axis, color, file, read, write, 
load, save,wave, image, table, data, apply, title, matrix, 
names)
patterns = sort(patterns)  #  optional
k = length(patterns)
#  open output file
options(verbose=FALSE)
zz - file(all functions.txt, open=wt)
sink(zz, type=output)
#  print the output to the file
cat(\n\n )
cat(pattern\tpackage\tfunction\r)
for (i in 1:k) {
cat(\n )
hits = allfuncs[grep(patterns[i], allfuncs[,2], ignore.case=TRUE),2]
hitpkg = allfuncs[grep(patterns[i], allfuncs[,2], ignore.case=TRUE),1]
hitpkg = gsub(\\d, , hitpkg)
labels = rep(patterns[i],length(hits))
newhits = cbind(labels, hitpkg, hits)
newhits =newhits[order(newhits[,3]),]  # sort data frame on 
basis of one column
cat(sprintf(fmt = %s\t%s\t %s\r, newhits[,1], newhits[,2], 
newhits[,3]))
}
cat(\n\n)
## back to the console
sink(type=output)
close(zz)  #  close the file
print(Finished)





[[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] categorized complete list of R commands?

2013-04-06 Thread Bretschneider SIG-R
Dear Rees Morrison,


Re:


 Franklin, I am very impressed.  I ran your code and am amazed at the output.  
 I want to use it in my efforts to figure out which are the most widely used 
 functions, so that I can concentrate on understanding those basics reasonably 
 well. 
 
 May I ask you two few questions?
 
 What additional code would create a table output, with the function name in 
 the left column, sorted alphabetically within a pattern, and the pattern of 
 the function in the column to the right.  Users could then sort by those 
 patterns, rename some to suit themselves, etc.
 

That would be handy, indeed, as well as in which package each function resides.
However, my own motive was that if you know the existence and exact name of 
(seemingly) relevant functions, you can find the full syntax etc. throught R's 
built-in help system. I'm not sure whether this would be simple, because grep 
yields a variable number of hits, which must then be combined with a fixed 
string value.   I'll think about it.



 Second, I assume this function searches base only?  Could you add a parameter 
 to the function so that it would search other, installed packages, such as 
 Hmisc or stringr or plyr?  If so, the table (or your output) would need to 
 identify the package.
 

search() gives a list of attached packages, so if you load all packages of your 
interest you 'll get all relevant functions.



 Third, the patterns might usefully include “wd”, “str”, and “names”.

Certainly; for others it might be model, summary etc. Users can extend the 
pattern list or load them from a text file, e.g.
patterns = read.csv(file.choose())


 
 I did not want to post this on R-Help because that site is much too 
 intimidating for a newcomer.  In that regard, Hadley Wickham sent the .csv 
 file where he compiled the base functions and stats functions.  I have done 
 one of my own, but it is not as comprehensive, but goes beyond base.
 


In my opinion it's better to CC the r-help, because someone in the vast R 
community might come up with a faster, or better, solution.




 Much obliged.
 
 Rees
 
 -- 
 Rees Morrison
 General Counsel Metrics, LLC (management consulting and data analytics)
 4 Hawthorne Ave.
 Princeton, NJ 08540-3840 USA
 (973) 568-9110
 Hosts www.lawdepartmentmanagementblog.com
 
Best wishes,


Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands






[[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] categorized complete list of R commands?

2013-04-05 Thread Bretschneider SIG-R

On 04 Apr 2013, at 07:34 , ivo welch wrote:

 every time I read the R release notes for the next release, I see many
 functions that I had forgotten about and many functions that I never knew
 existed to begin with.  (who knew there were bibtex facilities in R?
 obviously, everyone except me.)
 
 I wonder whether there is a complete list of all R commands (incl the
 standard packages) somewhere, preferably each with its one-liner AND
 categorization(s).  the one-liner can be generated from the documentation.
 I am thinking one categorization for function area (e.g., programming
 related for, say, deparse; and statistical model related for lm; and
 another categorization for importance (e.g., like common for lm and
 obscure for ..).  Such categorizations require intelligence.
 
 if I am going to do this for myself, I think a csv spreadsheet may be a
 good idea to make it easy to resort by keys.
 
 regards,
 
 /iaw
 
 
 Ivo Welch (ivo.we...@gmail.com)
 
   [[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.





A categorized list of functions would indeed come in handy.
So, based on Michael Weylandt's lines, I gave it a try:

 #  categorize functions.R
 #  Franklin Bretschneider
 #  after R-help: R. Michael Weylandt
 #  05-04-2013
 #  =
 nprint - function(x) print(x,quote=FALSE)
 allfuncs = unlist(sapply(search(), ls))
 names(allfuncs) - NULL
 patterns = c(print, plot, axes, axis, color, file, read, 
 write, load, save,wave, image, table, data, apply, title)
 patterns = sort(patterns)  #  optional
 n = length(patterns)
 nprint( )
 nprint( )
 for (i in 1:n) {
   nprint( )
   nprint(paste(Functions with,patterns[i],:))
 nprint(===)
   nprint(allfuncs[grep(patterns[i], allfuncs, ignore.case=TRUE)])
   nprint(- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
 -)
   }
 nprint( )
 nprint( )
 


The list of keywords can be adapted to one's own wishes.
Maybe this helps.

Best wishes,


Franklin


--
Franklin Bretschneider
Dept of Biology
Utrecht University
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] custom startup/welcome message

2013-04-04 Thread Bretschneider SIG-R
Dear lejeczek,

Re:

 hi everybody
 
 I wonder if there is a simple way, but not simple would be 
 ok too,
 to customize info/welcome page at session start time?
 
 what I'd like to do is to put together simple short howto / 
 dos  don'ts page for users,
 I'm thinking it would be great if it was possible




Indeed, you can put all kinds of things in the Rprofile.


I use this:

#  =   my own first-function
.First - function(){
cat(\n  R 2.15.2   Rprofile van 13-02-2013   \n\nFunctions 
added:\t sinc()\t permute()\t combine()\n dice(n)\t countif()\t pplot()\t 
lplot()\n ln()\t xmatplot()\t ascii()\t chr()\n to.dec()\t 
to.hex()\tincr()\tdecr()\n as.sci()\tas.eng()\tnprint()\nVectors added: eps, 
ans, xpoints, xcols\nText:lorem\n\n)
cat(Default Packages:,getOption(defaultPackages))
}
#  ==




This gets printed after R's built-in message.

As this text states, I also put my own functions in the Rprofile. Works fine.

Best wishes,


Franklin
--







Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] Plotting with basic plot

2013-03-16 Thread Bretschneider SIG-R
Dear Neuwirth Erich,


Re:


On 16 Mar 2013, at 19:18 , Neuwirth Erich wrote:

 When I run this code fragment
 
 x - (0:100)/100
 y - x^2
 plot(x,y,type=l,xlab=expression(x),ylab=expression(f(x)==x^2),
  main=Quadratfunktion)
 
 the exponent on the y-axis label is mutilated.
 How can the be changed with minimal effort?
 
 ggplot2
 does not have this problem:
 
 library(ggplot2)
 x - (0:100)/100
 y - x^2
 qplot(x,y,geom=line,xlab=expression(x),ylab=expression(f(x)==x^2),
  main=Quadratfunktion)
 
 __
 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.


# The left margin can be chosen wider, e.g.bij putting:
par(mar=c(4,5,4,4))
#  before the plotting statement.

Beste wishes,


Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] low pass filter analysis in R

2013-02-08 Thread Bretschneider SIG-R
Dear Janesh,


Re:

 Dear Franklin Bretschneider,
 
 Thank you so much for your reply and explanation about the filter using the 
 stats and signal package. 
 
 I decided to opt the filter method in signal package. I have a simple 
 question about the cut off frequency here. 
 
 I have 30 minute collected tidal data and I want to use the 48 hour low pass 
 filter to my data to remove the fluctuations and then get only the residuals. 
 What should be the cutoff frequency in my case ? I have tried to figure out 
 cut off frequency with the following rationale : . 
 
 The parameters for butter filter are n, Wn and type. In the help, Wis 
 defined as critical frequencies of the filter. W must be a scalar for 
 low-pass and high-pass filters, and W must be a two-element vector c(low, 
 high) specifying the lower and upper bands. For digital filters, W must be 
 between 0 and 1 where 1 is the Nyquist frequency.
 
 A value of 1 corresponds to half the sampling frequency. In my case the 
 sampling frequency is 2 hr^-1. Hence a value of 0.01 corresponds to a 
 frequency cutoff of .01*1 = .01 hr^-1 or 100 hrs time. Using unitary method, 
 if 100 hours cut off frequency is 0.01 then 48 hours cut off frequency is 
 0.01/100*48 = 0.0048 hr^-1 . Is that correct ?
 
 Thank you so much
 
 Janesh
 


With digital filters (called z-plane in the signal package), the cut-off 
frequency must indeed be given as a fraction of the Nyquist freqency.

With your tidal data, taken at 2 samples per hour, the nyquist is 1 per hour. 
So, a cutoff interval of 48 h means a cutoff frequncy of 1/48 f(nyq) , or 
0.020833. This must be fed into the butterworth function.

Note btw that at the cut-off frequency, the amplitude is still rather high 
(about 0.707), so the tidal signal (period about 12.5 h) will not be attenuated 
much.
I hope this helps. It's always best to check with a simple example, such as an 
f= 1/48 sine, which after your filter should be reduced to an amplitude of 
0.707). Then check with a simulated tidal signal (say, a sine of about 12:25 h 
period). 
With such simple tests, I often find my own programming errors.
Best wishes,


Franklin
--


Franklin Bretschneider
--
Dept Biology
Kruyt Building W711
Padualaan 8
3584 CH Utrecht
The Netherlands






[[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] Add text A, B, C and D on multiple ordered plot

2013-02-08 Thread Bretschneider SIG-R
Dear Fabrice Tourre,


Re:



 John Kane,
 
 Thanks. It makes some of sense. But it seems not exactly what I want.
 I just remember it need using mtext and adjust margin. I saw such of
 example long time ago, but I have forgotten it.

(etc...)




Maybe this is what you're after?

Fiddled a bit with the margins:


a- rnorm(1000,0,1)
b-rnorm(1000,0,2)
c-rnorm(1000,0,3)
d-rnorm(1000,0,4)
quartz(w=6,h=8)
par(mfrow=c(2,2))
#par(mai=c(1,0,1,1))
par(mar=c(3,2,4,1))
#par(plt=c(1.1,1.1,1.1,1.1))
tlin=2
hist(a)
mtext(A,3, line=tlin, adj=0, cex=2)
hist(b)
mtext(B,3, line=tlin, adj=1, cex=2)
hist(c)
mtext(C,3, line=tlin, adj=0, cex=2)
hist(d)
mtext(D,3, line=tlin, adj=1, cex=2)


Hope this helps,
Best regards,


Franklin Bretschneider


--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] low pass filter analysis in R

2013-02-07 Thread Bretschneider SIG-R

Dear Janesh Devkota,


Re:

 
 Hello R users,
 
 I am trying to use R to do the low pass filter analysis for the tidal data.
 I am a novice in R and so far been doing only simple stuffs on R. I found a
 package called signal but couldn't find the proper tutorial for the low
 pass filter.
 
 Could anyone point me to the proper tutorial or starting point on how to do
 low pass filter analysis in R ?
 
 Thank you so much.
 
 Janesh




Indeed, filters are in both the stats and the signal packages.
The simplest is to define a running average smoothing, e.g.

if your data is called y:

yfiltered = stats:::filter(y, c(1,1,1,1,1,1,1)/7)

So, smooth the data by the filter c(1,1,1,1,1,1,1)/7
Note that the first 3 and last 3 data points are lost.
The longer the filter, the more data at the start and the end of your data will 
be lost.


The signal package allows more sphisticated forms of filter.
In addition, it contains functions to compute filter types well-known in signal 
analysis, such as butterworth and chebysheff filters.

A second-order butterworth filter with a cutoff at 0.1 x the sampling frequency:

myfilter = butter(2, 0.1, type = 'low', plane='z')  

Apply this:

yfiltered = signal:::filter(y, x) # apply filter

Note that loading the signal package may mask the filter from stats.
Hence the call with the ::: in it.

Succes.

Best wishes,



Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] low pass filter analysis in R

2013-02-07 Thread Bretschneider SIG-R

Dear Janesh Devkota,



Sorry, I forgot an edit.
The last command should read:

yfiltered = signal:::filter(myfilter, y) # apply filter

Best wishes,



Franklin Bretschneider


--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] Starting with R

2012-12-30 Thread Bretschneider SIG-R

On 30 Dec 2012, at 12:22 , Siddhant Gupta wrote:

 I have installed R on my machine.
 
 Can anyone now suggest to me the best book/e-book from where I can learn
 the R language most efficiently?
 
 Thanks in advance
 
 -- 
 Siddhant Gupta
 III Year
 Department of Biotechnology
 IIT Roorkee
 India
 
   [[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.



Yes, quite a lot!

At:

http://ftp.iitm.ac.in/cran/


Succes, and
Best wishes,



Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] what is the function naming convention?

2012-11-04 Thread Bretschneider SIG-R
Dear R people,



In typing names of functions (built in or from a package) I often guess wrong, 
and have to look the name up.
In other words, I don't understand the logic in naming functions (if there is 
any):

-  most names are plain, lower case:  cos,  plot,  sapply,  t,  toupper,  
unserialize,  (etc) 

-  some are capitalized:  Filter,  Machine,  Map,  NCOL,  RNGversion,  T  (etc) 

-  many are dotted:  as.complex,  as.data.frame.array,  merge.data.frame,  
write.dcf  (etc) 

The manual Creating R Packages states that it depends on the classes and 
instances. I couldn't find more hints.

And there's more:

-  using underscore characters:  check_tzones,  Cstack_info,  R_system_version  
(etc)

-  using interCapping:  closeAllConnections,  rawToChar,  rowSums,  toString,  
tryCatch,  writeLines  (etc)

-  using dots and intercapping:  as.Date,  julian.Date,  toString.default  (etc)



So, an entire zoo of function names.
Did I miss a system, or is it arbitrary (within the set of accepted characters) 
? 
What is the best way to name one's own functions?

Thanks in advance,



Franklin Bretschneider

Utrecht University
Dept Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] Reading multiple files

2012-09-26 Thread Bretschneider SIG-R

On 26 Sep 2012, at 16:11 , Silvano Cesar da Costa wrote:

 Hi,
 
 I have 35 data files for reading. I would like get a program for
 performing reading of 35 files at once.
 All are of the type: Dados1.raw, Dados2.raw and so on.
 
 If the files have the same number of columns, I can read with the
 following commands:
 
 rm(list=ls())
 filenames = list.files(path=~/Silvano/Arq, pattern=Dados+.*raw)
 names = substr(filenames, 1, 7)
 
 for(i in names){
  filepath = file.path(~/Silvano/Dados, paste(i, .raw, sep=))
  assign(i, read.delim(filepath,
   colClasses=c(rep(character, 5), rep(numeric, 5)),
   sep = ))
 }
 
 It happens that the files have different number of columns. And I can't
 solve the problem.
 
 Any suggestions?
 



Dear Silvano Cesar da Costa,


You can read an entire folder by analysing the path.
I wrote this program to convert wave files, but it can be applied to any file 
type.
Just change the few lines (if ywave... etc) into your own operations:


#  select FOLDER with WAV-files
fnam = dirname(file.choose())
print(); print(FILES)
print(list.files(fnam))
print(); print(DIRS)
print(list.dirs(fnam, full.names=FALSE))
print(); print(RECURSIVE FILE LIST)
filist = list.files(fnam, recursive=TRUE, pattern=wav)
print(filist)
filist1 = paste(fnam,/,filist, sep=)
nfiles = length(filist1)
#  
#  filenames loop ===
for(i in 1:nfiles) {
inname=filist1[i]
ywave=readWave(inname)
ster=ywave@stereo
if (ster==stereo) {} #  wat dan??
srate=yw...@samp.rate
ywave2=ywave
if (ywave2@bit==8) {
ywave2@left=(ywave2@left-128)*255
ywave2@bit - 16
}
if (ywa...@samp.rate10) {
ywa...@samp.rate - ywa...@samp.rate * 10
}
if (ywa...@samp.rate != 312500) {
ywave2 - resamp(ywave2,f=ywa...@samp.rate,g=312500, 
output=Wave)
}

outname=paste(dirname(inname), /*,basename(inname), sep=)
writeWave(ywave2,outname)
}


Best wishes,

Franklin Bretschneider

Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands
f.bretschnei...@uu.nl

__
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] how to get list of files within a particular local file folder

2012-07-04 Thread Bretschneider SIG-R
Dear Ajay Ohri,

Re:

 Dear List,
 
 Say I can use getwd() and setwd() to change my working directory. How can I
 read in all the files within that directory using command line (like a ls()
 but for the path specified)
 

I use this function,

#  functions
getFolder - function(pat)
{
txt=file.choose()
#cat(txt,'\n')
pos=0
fname=basename(txt) 
#cat(paste(\nFilename found is: ,fname,'\n'))
foln = dirname(txt)
cat(paste(\nFolder name found is: ,foln,'\n'))
drtext=dir(foln, pattern=pat, full.names = TRUE)
#cat('\n\n\n\n') 
return(drtext)
}


Best,

Franklin

Dr F. Bretschneider
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] how to plot a nice legend

2012-02-12 Thread Bretschneider SIG-R
Dear Jonas Stein,


You may add a line defining a large margin to harbour the legend,
such as:

par(mai=c(0.5, 0.5, 0.5, 1.8))   #  enlarged right margin
plot(1:10)
legend(right, legend=c(one, two), inset=-0.2, xpd=NA)


Kind regards,



Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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] How to loop on file names

2012-01-17 Thread Bretschneider SIG-R
Dear Hélène Genet,


Re:

 Dear all,
 
 I need to do the same procedure on several files. But I don't know how to 
 refer to the file name.
 Here is an example of what I am trying to do.
 
 List of files: file1(A,B,C, D1...Dn), file2(A,B,C,E1,...,En), 
 file3(A,B,C,F1,...,Fn)
 
 Procedure I want to apply on each file:
 
 dft - melt(df,id=c('A','B','C'))
 dft$X - substr(dft$variable,1,3)
 dft$Y - substr(dft$variable,4,8)
 dft1 - cast(dft, A+B+C+X ~ Y,value=response)
 
 As you see all the files contains the same 3 variables A,B,C that I use in 
 the procedure.
 So I want to apply the procedure on all the file in a loop.
 Something like :
 
 filelist - c('file1' , 'file2' , 'file3')
 
 for (i in 1:3) {
 filename - filelist[i]
 ...
 }
 
 Any suggestion to refer to these files in this loop?
 
 Thanks you in advance,
 
 Helene
 
 -- 
 Hélène Genet, PhD
 Institute of Arctic Biology
 University of Alaska Fairbanks
 Irving I Blg, Room 402
 Fairbanks AK 99775
 
 Phone: 907-474-5472
 Cell: 907-699-4340
 Email: hge...@alaska.edu
 
 __
 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.
 



I use this procedure to point to a folder (of WAV files in this example) and 
process all those files in a loop:


#  select FOLDER w. WAV-files
fnam = dirname(file.choose())# choose any one file from the folder (= 
directory)
filist = list.files(fnam, recursive=TRUE, pattern=wav)
filist1 = paste(fnam,/,filist, sep=)
nfiles = length(filist1)
#  
#  filenames loop ===
for(i in 1:nfiles) {
inname=filist1[i]
ywave=readWave(inname)  # read the i'th file  (wav as an example, can 
be any filetype you need)
ywave2=ywave  # output is the same as input (yet)
###
###   DO ANY PROCESSING YOU WANT HERE to change ywave into ywave2
###
outname=paste(dirname(inname), /*,basename(inname), sep=)
writeWave(ywave2,outname)
}


I took these few lines out of a larger program with wave file processing not 
relevant here.
Hope I didn't forget something, and that this works for your case,


Beste wishes,



Franklin Bretschneider
Utrecht University
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

__
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.