Re: [R] Implementing R's recycling rule

2010-10-19 Thread Richard . Cotton
x - c(1, 2, 3) n - 10 ## so using the recycling rules, I would like to get from FUN(x, n)==1 ## I am doing: xRecycled - rep(x, length.out=n)[n] This works, but it seems to me that I am missing something really basic here - is there more straightforward way of doing this? x[n %%

Re: [R] adding the mean and standard deviation to boxplots

2008-02-04 Thread Richard . Cotton
As for the standard deviation, are you sure you want this? Standard deviation only makes sense if the data are normally distributed... -- -- This is false, of course. What you probably meant to say is something like: The sample standard deviation may not tell you what you

Re: [R] inserting text lines in a dat frame

2008-02-06 Thread Richard . Cotton
I am trying to prepare a bed file to load as accustom track on the UCSC genome browser. I have a data frame that looks like the one below. x V1V2 V3 1 chr1 11255 55 2 chr1 11320 29 3 chr1 11400 45 4 chr2 21680 35 5 chr2 21750 84 6 chr2 21820 29 7 chr2 31890 46 8 chr3 32100

Re: [R] Help with write.csv

2008-02-11 Thread Richard . Cotton
I am new to R. I am using the impute package with data contained in csv file. I have followed the example in the impute package as follows: mydata = read.csv(sample_impute.csv, header = TRUE) mydata.expr - mydata[-1,-(1:2)] mydata.imputed - impute.knn(as.matrix(mydata.expr)) The

Re: [R] Number of digits of a value for problem 7.31 RFAQ SOLVED not really

2008-02-18 Thread Richard . Cotton
Actually (after some trials) there is a little problem when faced with zeros... getndp(1.0) [1] 0 Are you sure this isn't what you want? 1.0 is just 1 in disguise, and round(1.0, 0) is the same as round(1.0, 1) anyway. Note that I thought on a very different way which was starting

Re: [R] Permutation Test

2008-02-21 Thread Richard . Cotton
Am I right in thinking that the correct way of working out how many possible permutations there can be in this instance is: N! / (n1!) (n2!) (n3!)... (ni!). Where N is the number of taxa (14) and (for character 2) n1 could be 'number of state zeros' (i.e., 2), n2 could be 'number of state

Re: [R] Simultaneously summarizing many models

2008-02-22 Thread Richard . Cotton
Let´s say I have 10 models, each named m1,m2,m3..., and I would like to summarize them automatically and simultaneously - e.g., to extract parameter estimates later on from all models; how can I do that? I have tried: x=1:10 #this creates some example data y=rnorm(10) m1=lm(x~y)

Re: [R] Avoiding overplotting of text.

2008-02-25 Thread Richard . Cotton
I am plotting some data, and use text() to get variable names next to points on the graph. What is the best way to make sure that these text labels are readable and not overlapping when two datapoints are close? I've tried using jitter(), but the effect is random and doesn't always give a

Re: [R] Loading user defined functions autometically each time I start R

2008-02-27 Thread Richard . Cotton
I wrote some user defined function for my own. Now I want to get a mechanism so that every time I start R, those function will automatically be loaded in R without manually copying pasting. Can gurus here pls tell me how to do that? Or I have to build my own packages bundled with those

Re: [R] looping through data frames in a workspace

2008-03-04 Thread Richard Cotton
lucy b wrote: I have a workspace containing only data frame objects. I would like to loop though each one and clean-up text columns in them. How can I have R loop through the list? I have tried to find an answer in R help but the closest solution I can find is to make a static list of

Re: [R] automatically save graphic

2008-03-04 Thread Richard Cotton
mysimbaa wrote: I write some code which produce a graphic Now I try at the end to output it (bitmap or jpeg) like this way : - pop up window asking me to choose a path where to save my picture - choose name for this picture Your message isn't very clear, so forgive me if I have

Re: [R] Excel export into R

2008-03-06 Thread Richard . Cotton
I have this in excel Control 543_BU 123_AT 432_CU I want to be able to import to R so that it will read like this c-c(543_BU,123_AT,432_CU) See the help page for read.csv ?read.csv ...and the R Data Import/Export manual http://cran.r-project.org/doc/manuals/R-data.html Two things

Re: [R] 1-pnorm values in a table

2008-03-06 Thread Richard . Cotton
I've read in a csv file (test.csv) which gives me the following table: Hin1 Hin2 Hin3Hin4 Hin5 Hin6 HAI1 9534.83 4001.74 157.16 3736.93 484.60 59.25 HAI2 13272.48 1519.88 36.35 33.64 46.68 82.11 HAI3 12587.71 5686.94 656.62 572.29 351.60 136.91 HAI4

Re: [R] Error

2008-03-07 Thread Richard . Cotton
I need some help, because I don't know how this error means: Error: variables ?Output1?, ?Output2?, ?Output3?, ?Output4?, ?Output5? were specified with different types from the fit Execution halted Can you help me? No! Please read the posting guide at

Re: [R] Passing function to tapply as a string

2008-03-07 Thread Richard . Cotton
Was wondering if it is possible to pass function name as a parameter Yes. This isn't exactly what you wanted, but it demonstrates the principle. x = rnorm(5) [1] -0.6510448 0.4591730 1.3225205 1.2314391 -0.0888139 myfun - function(fname, x) eval(parse(text=paste(fname,(x),sep=)))

Re: [R] Puzzled at generating combinations

2008-03-18 Thread Richard . Cotton
I have two data frames. Suppose the first has rows r1 r2 r3 and the second has rows R1 R2 R3 I'd like to generate the data frame: r1 R1 r1 R2 r1 R3 r2 R1 r2 R2 r2 R3 r3 R1 r3 R2 r3 R3 Try: col1 - paste(r, 1:3, sep=)

Re: [R] sort

2008-03-19 Thread Richard . Cotton
Is there any function in R which sorted data as x1 - c(1,3,2,4,5,1) x2 - c(2,0,2,3,5,2) TheData - data.frame(x1,x2) TheData1 - sort(TheData, by=c(x1,x2)) Yes; see ?order and the R FAQ 7.23 http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-sort-the-rows-of-a-data-frame_003f Regards,

Re: [R] Moving data between R and Matlab back and forth?

2008-03-27 Thread Richard . Cotton
I realized that not everyone has Matlab and that basically the issue is purely how to deal with the returned data in R, so I have revised my example code and made it easier to copy-paste and run: #Make a data frame in R Maker - factor(c(HP, HP, Sony, DELL, whitebox,

Re: [R] Comparing proportions between groups

2008-03-28 Thread Richard Cotton
Lila86 wrote: I have two groups (men and women) and I know per group how many of them smoke or don't smoke (women 40 of 200; men 100 of 300). I would like to know how I can compare in R if men and women differ significantly in their smoking. However, because there are more men in the

Re: [R] hsv2rgb in R

2008-03-31 Thread Richard . Cotton
I noted that there is a hsv2rgb in the C-API, but no corresponding function in R, while rgb2hsv is available in R. Does the functionality of hsv2rgb hide under some other name? I agree that it does seem like such a function ought to exist. You can use col2rgb(hsv(...)) to get what you

Re: [R] Reorder the x-axis using lattice

2008-03-31 Thread Richard . Cotton
Is there a way to reorder the xaxis using lattice. Using the following data, the x-axis is ordered as BP GH MH PF RE RP SF VT but I would like the x-axis to be ordered as PF RP BP GH VT SF RE MH. Kön Skalor Tillfälle Medelvärde 1 Kvinnor BP 1-inskrivning 36.45283

Re: [R] how to apply a self-written function to a data frame

2009-07-06 Thread Richard . Cotton
I have written a function in order to analyse gaze paths. It works with the test data but when I try to apply the function to a data frame that stores the real data in columns I receive the error message that the In if (pp 1) { : condition has length 1 only the first element will

Re: [R] rle

2009-07-07 Thread Richard . Cotton
I have an other problem, I have this vector signData with an alternation of 1 and -1 that corrispond to the duration of two different percepts. I extracted the durations like this: signData- scan(dataTR10.txt) dur-rle(signData)$length I think that last line should be

Re: [R] HELP: BRUGS/WinBUGS/RBUGS Response is a combination of random variables

2009-07-20 Thread Richard . Cotton
Is there anyone know if BUGS language allows the combination of variables as response It seems doesn't work in my model. The problem is between two ##. modelCompile(numChains=1) multiple definitions of node bm[1] ### bm[iter] -

Re: [R] Regression for loop test HELP! URGENT!

2009-07-20 Thread Richard . Cotton
I'm new to R, and I've sent this message as a non-member, but since it's pretty urgent, I'm sending it again now I'm on the mailing list (Thanks Daniel for your suggestion nevertheless). I have calculated a regression in the form of M ~ D + O + S, and I would like to take this regression

Re: [R] Histograms on a log scale

2009-07-20 Thread Richard . Cotton
I would like to be able to plot histograms/densities on a semi-log or log-log scale. # Get a random log-normal distribution r - rlnorm(1000) # Get the distribution without plotting it using tighter breaks h - hist(r, plot=F, breaks=c(seq(0,max(r)+1, .1))) # Plot the distribution using

Re: [R] sorting by the row names

2008-08-21 Thread Richard . Cotton
is it possible to sort a file by the row names? I presume you mean a data frame rather than a file. In which case the answer is yes: df - data.frame(a=1:10, b=rnorm(10), row.names=sample(letters[1:10])) df[order(rownames(df)),] Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] swap

2008-08-22 Thread Richard . Cotton
I wonder if there is any swap function in R that does the following: x - seq(1,10,12) This just makes x equal to 1. I'm guessing you meant something like x - 1:10 x1 - swap(x) x1 1 8 3 4 5 6 7 2 10 It's not terribly clear what you want swap to do. You can reorder the elements of x

Re: [R] swap

2008-08-22 Thread Richard . Cotton
Hello Richie, I would like to do three (or k) swap steps in each step just 2 ID recursive swaping x - 1:10 swap - function(x){ a - sample(x,2) x[x==a[1]] - swap[2] x[x==a[2]] - swap[1] return(x) } swap(swap(swap(x))) - mix I tried my best with a response before, but if you

Re: [R] String search: Return closest match

2008-08-26 Thread Richard . Cotton
I have to match names where names can be recorded with errors or additions. Now I am searching for a string search function which returns always the closest match. E.g. searching for Washington it should return only Washington but not Washington, D.C. But it also could be that the list

Re: [R] tryCatch

2008-09-01 Thread Richard . Cotton
I am trying to debug a program, and I think tryCatch will help. The functions involved process through so many times before I encounter the error, things are a bit slow to use debug and browser(). I've read the help file and postings on conditions, and am still having trouble.

Re: [R] warning with hist

2008-09-01 Thread Richard . Cotton
I don't understand the warning I get when executing the following code: x - rnorm(100) h - hist(x, plot= FALSE, freq = FALSE) The warning is Warning message: In hist.default(x, plot = FALSE, freq = FALSE) : argument ‘freq’ is not made use of The explanation is pretty simple. freq

Re: [R] Projecting Survival Curve into the Future

2008-09-04 Thread Richard . Cotton
I have a survivor curve that shows account cancellations during the past 3.5 months. Â Fortunately for our business, but unfortunately for my analysis, the survivor curve doesn't yet pass through 50%. Â Is there a safe way to extend the survivor curve and estimate at what time we'll hit

[R] controlling lattice plot ticks with relation=free

2008-09-05 Thread Richard . Cotton
How do you persuade lattice to draw tick marks on both the left and right side of the y-axis, when relation=free in the scales component? #Ticks appear on both sides histogram(~height|voice.part, data=singer) ##Ticks only on left histogram(~height|voice.part, data=singer,

Re: [R] controlling lattice plot ticks with relation=free

2008-09-05 Thread Richard . Cotton
How do you persuade lattice to draw tick marks on both the left and right side of the y-axis, when relation=free in the scales component? #Ticks appear on both sides histogram(~height|voice.part, data=singer) ##Ticks only on left histogram(~height|voice.part, data=singer,

Re: [R] data import

2008-09-11 Thread Richard . Cotton
I have a data set containing 2,122,164 records and 38198952 fields. I can not import this data due to momory problem. Is there a way to solve this problem? 1. Filter the data before you import it. Do you really need all 38 million fields? Can you ignore some of the 2 million records?

Re: [R] how to plot monthly mean data showing missing months

2008-09-12 Thread Richard . Cotton
As per my attached script I am ploting monthly mean data which has missing months. But in the plot missing months are not shown (plot attached). Kindly help how to show complete plot (Jan-Dec) with missing months. I don't accept scripts from strangers, but I guess the problem looks like

Re: [R] HI

2008-09-16 Thread Richard . Cotton
Does anyone know an easy way to convert all the zero values in a imported csv table into NA's Depends on the data structure you gave your imported table. In a single numeric vector (named, say, vec), the syntax is is.na(vec[vec==0]) - TRUE That throws errors for me. An alternative is

Re: [R] Setting user colors in barchart

2008-09-16 Thread Richard . Cotton
I have a basis question regarding the use of color in the lattice package. I read the ?barchart help page and searched the R archives but could not understand how to do it. I just need to plot a barchart using specific colors for my groups, e.g. green and red instead of the default lattice

Re: [R] Setting user colors in barchart

2008-09-16 Thread Richard . Cotton
Thank you for a clear example, it works. I tried to play with superpose.polygon before to no avail, this clarifies things. You're welcome. Another question: would you know how to add gridlines to the plot? I'd like to have a few horizontal gridlines on my barchart plot for better

Re: [R] using for variable as rowname

2008-09-17 Thread Richard . Cotton
Is there a way to use the cycle variable for rowname? v=1:6 for (a in 1:3){ for (b in 4:5) { v=rbind(v,a.b=1) } } v This above obviously does not work, but I couldn't find out how to use a and b to construct a rowname like 14, 15, 24, 25. Not pretty, but this does the trick.

Re: [R] Question about panel.points

2008-09-17 Thread Richard . Cotton
I'm trying to plot graphs using lattice with this script : xyplot(Y ~ X | factmod, panel = function(x, y) { panel.grid(h=-1, v=-1, col=gray) panel.xyplot(x, y, type=p, pch=20) panel.points(50,Idata, data=devdata, col=red) - this

Re: [R] Oja median

2008-09-18 Thread Richard . Cotton
Can we get the code for calculating Oja median for multivariate data RSiteSearch(oja median) returns a link to this R-help post with code http://finzi.psych.upenn.edu/R/Rhelp02a/archive/12781.html Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] Writing greek letters and subscripts in graph

2008-09-18 Thread Richard . Cotton
I would like to write Greek letters followed by subscripts in a graph (on the X-axis and in a legend). I would appreciate any help. See FAQ 7.13 and ?plotmath for examples. Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] how to keep up with R?

2008-09-19 Thread Richard . Cotton
The good thing about training and evangelization ... I spent quite a lot of time evangelizing about R when I first started my current job. Eventually my boss told me I was an R-Soul, or something that sounded like that anyway. ; ) Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] xyplot problem

2008-09-23 Thread Richard . Cotton
I am trying to produce some panels with dots in an X/Y plane where the diameter of the dots indicates a Z value (like e.g. earthquake maps where dot sizes indicate magnitudes and X/Y the location). This works fine with xyplot, e.g.: xyplot(1:3~1:3,cex=1:3,pch=16) However, when I do

[R] adjusting textsize and spacing in mosaic (vcd package)

2008-09-26 Thread Richard . Cotton
I'm trying to find a way to change the font size in a mosaic plot (the grid version, not the base graphics one). Here's an example to demonstrate: #Basic plot library(vcd) mosaic(HairEyeColor, shade = TRUE) #Bad first guess: this stops the default cell colouring, and doesn't change the font

Re: [R] sequential sum of a vector...

2008-07-23 Thread Richard . Cotton
x=1:80 I want to sum up first 8 elements of x, then again next 8 elements of x, then again another 8 elements. So, my new vector should look like: c(36,100,164,228,292,356,420,484,548,612) I used: aggregate(x,list(rep(1:10,each=8)),sum)[-1] or

Re: [R] NAs - NAs are not allowed in subscripted assignments

2008-07-24 Thread Richard . Cotton
I ran into some trouble handling missing values. Assume 2 vectors (numeric) including NAs a - c(rep(seq(1,4),4),NA,NA) b - c(sample(1:2,14,replace=T),NA,NA,1,2) I want to replace the values of vector a that are smaller than 2 and larger than 3 into NAs only in case vector b equals 1

Re: [R] Fit a 3-Dimensional Line to Data Points

2008-07-25 Thread Richard . Cotton
I am new to R, and was wondering how to do 3D linear regression in R. In other words, I need to Fit a 3-Dimensional Line to Data Points (input). I googled before posting this, and found that it is possible in Matlab and other commercial packages. For example, see the Matlab link:

Re: [R] Panel of pie charts

2008-07-29 Thread Richard . Cotton
I am looking to making a panel of pie charts fo some of my dritribution data . I was wondering if there is a way in any R package to write a small script to do so. pie() will do you a one-off pie chart, but there is no equivalent using grid/ lattice graphics. You could write a panel.pie

Re: [R] try question

2008-07-29 Thread Richard . Cotton
try(log(rnorm(25)),silent=TRUE) [1] -0.26396185 NaN NaN -0.13078069 -2.44997193 -2.15603971 NaN 0.94917495 0.07244544 NaN [11] -1.06341127 -0.42293099 -0.53769569 0.95134763 0.93403340 NaN -0.10502078 NaN 0.30283262 NaN [21]

Re: [R] Need help

2008-07-30 Thread Richard . Cotton
Can someone help me to understand the meaning of the following R line? list(fk5 ~ .) fk5 ~. is a formula, most likely used by a regression (or similar model). fk5 is the response variable, and the dot is a placeholder for 'whatever was on that side of the formula before'. (This is usually

Re: [R] Identifying common prefixes from a vector of words, and delete those prefixes

2008-07-31 Thread Richard . Cotton
For example, c(dog.is.an.animal, cat.is.an.animal, rat.is.an. animal). How can I identify the common prefix is .is.an.animal and delete it to give c(dog, cat, rat) ? foo - c(dog.is.an.animal, cat.is.an.animal, rat.is.an.animal) sub(.is.an.animal, , foo) Being pedantic, .is.an.animal is a

Re: [R] problems with 'eval' and 'parse' with strings

2008-04-02 Thread Richard . Cotton
p=v= q=5 eval(parse(text=paste(p,q,sep=))) ... then the value of v is 5, OK. but I can't with strings, for example: p=v= q=hello friend eval(parse(text=paste(p,q,sep=))) .. error Try: eval(parse(text=paste(p,',q,',sep=))) Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] Thinking about using two y-scales on your plot?

2008-04-03 Thread Richard Cotton
thegeologician wrote: ... very often time-series plots of some values are given rather to show the temporal correlation of these, than to show the actual numerical values! The same applies for plots of some sample values over distance (eg. element concentration over a sample or

Re: [R] Thinking about using two y-scales on your plot?

2008-04-07 Thread Richard Cotton
thegeologician wrote: A plot of the actual temperature during a year (or thousands of years, as people in palaeoclimate-studies are rather used to) is just so much more intuitive, than some correlation-coefficients or such. I know I'm largely speaking to statisticians in this forum, but

Re: [R] Quick fix formatting

2008-04-07 Thread Richard . Cotton
I have two data frames and am running a loop to match similar rows. However the matching is not working well, and I suspect it is because of the different formats of columns. For example, in col. 1 of dataframe 1 the nummbers are formatted as 1,2,3,4,5,6,7,8,9...31 However in col. 1

Re: [R] Replace values according to conditions

2008-04-09 Thread Richard . Cotton
I have the following data called mydata in a data.frame Col1 Col2 Col3 Col4 Col5 1 2 46 7 8 8 73 5 4 4 56 7 I want to replace the data according to the following conditions Condition 1 if data = 3, replace with -1 Condition 2

Re: [R] problem with basic boolean selection in sequence

2008-04-09 Thread Richard . Cotton
I have a surprising problem while selecting values in a sequence created with the seq() function... ... test2-seq(from=0,to=1,by=.1) ... test2==0.3 [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE ... Does anyones has an explanation and a solution ? I suspect that

Re: [R] Changing default plot behaviour

2008-04-09 Thread Richard . Cotton
How would I make the default behaviour of my plots produce output such as the following (i.e. tick marks inside on all axes, labels only on two (arbitrary?) sides) without needing the five additional commands each time? plot(1:10, axes=FALSE) axis(1, tcl=0.5) axis(2, tcl=0.5) axis(3,

Re: [R] Beautifying axis tick labels

2008-04-10 Thread Richard . Cotton
For example, the y axis shows 0 50 150. Is there any way to beautify the tick labels to get 0 5 10 15, and at the top of y-axis x10^5 (superscript 5) ? My plots all have different ylim, how to perform the beautification automatically ? plot((0:15)*1e5, yaxt=n, ylab=) axis(side=2,

Re: [R] looping problem

2008-04-14 Thread Richard . Cotton
I would like to do looping for this process below to estimate alpha beta from gamma distribution: Here are my data: day_data1 - 123456 789 10 11 12 13 14 15 16 17 18 19 20 21 22 23 1943 48.3 18.5 0.0 0.0 18.3 0.0 0.0

Re: [R] Is this an artifact of using which?

2008-04-14 Thread Richard . Cotton
The (imho) unintuitive behaviour is to do with the subsetting function [.factor, not which. There are a couple of workarounds: In that case, your intuition needs readjustment There are other systems which (de facto) drop unused levels by default, and it is a real pain to work

Re: [R] Function redefinition - not urgent, but I am curious

2008-04-21 Thread Richard . Cotton
Suppose I write: f1 - function(x) x + 1 f2 - function(x) 2 * f1(x) f2(10) # 22 f1 - function(x) x - 1 f2(10) # 18 This is quite obvious. But is there any way to define f2 in such a way that we freeze the definition of f1? f1 - function(x) x+1 f1frozen - f1 f2 - function(x)

Re: [R] Choice of notch size in R

2008-04-21 Thread Richard . Cotton
Is there a way to modify the choice of notch size [1] in R's boxplot routine from outlining a 5% significance region, to say 1% or lower? Yes, but it's not as simple as specifying the significance level. You'll have to update the function boxplot.stats, specifically the line conf - if

Re: [R] bar-chart help

2008-04-22 Thread Richard . Cotton
I have a table like below outside R environment Varible_Name Labels Bad_Percent Good_Percent Var1_Postal_Code_Availibility 1 0,149367931 0,850632069 0 0,19709687 0,80290313 Variable_Name column contains a single entry, the variable name, this is the title of

Re: [R] Research Notes

2008-04-22 Thread Richard . Cotton
What has become more and more obvious to me after I started using R about two years ago is that I have collected a large number of data files, scripts, and workspaces (.Rdata files) in several catalogs on my computer. It is also obvious that my memory is not up to the task of keeping

Re: [R] Combine Values into a Vector or List

2008-04-28 Thread Richard . Cotton
x1-paste(A, 1:6, sep = ) x2- round(rgamma(6,2,1)) x3-paste(B, 1:6, sep = ) x4- round(rgamma(6,2,1)) data1 - data.frame(x1,x2,x3,x4) I would like to get data2 - c(A1=4, A2=1, A3=0,...) Is there any standard for such a case? I presume that 4, 2, 0 are the first few values of x2. In which

Re: [R] how to find the minimum

2008-04-29 Thread Richard . Cotton
I am a new R user, and not very good at statistics and maths I find it difficult to find the minimum of this item: ((p*(b-1)-1)*(p+1)^(b-1)+1)/p^2 It seems that the method optim can find the minimum. I tried several times , but R constanly tells that failure to find b or

Re: [R] efficient code - yet another question

2008-05-01 Thread Richard . Cotton
I've been trying to find a way to improve (if possible) the efficiency of the code, especially when the number of components to calculate is higher than 100. pca.nipals - function(X, ncomp, iter = 50, toler = sqrt(.Machine$double.eps)) # X...data matrix, ncomp...number of components, #

Re: [R] Help with apply and split...

2008-05-02 Thread Richard . Cotton
datg=t(sapply(split(datgic, datgic$NPERMNO, drop=TRUE), function(x){return( x[nrow(x),] )})) I get something like this... GVKEY NPERMNO GIC year 10001 12994 10001 55102010 2007 10002 19049 10002 40101015 2007 10009 16739 10009 40101010 1999 Has this been made

Re: [R] to extract particular date/data

2008-05-02 Thread Richard . Cotton
If I have this daily rainfall data, how do call a particular day? Year,Month,Day,Amount 1900,12,22,1.3 1900,12,23,0 1900,12,24,0 1900,12,25,0 1900,12,26,0 1900,12,27,0 1900,12,28,0 1900,12,29,4.8 1900,12,30,0.3 1900,12,31,0.5 1901,1,1,0 1901,1,2,3 1901,1,3,0 1901,1,4,0.5

Re: [R] removing rows from matrix

2008-05-02 Thread Richard . Cotton
Hi, I have a problem regarding matrix handeling. I am working with a serie of matrixes containing several columns. Now I would like to delete those rows of the matrixes,that in one of the columns contain values less than 50 or greater than 1000. Try this: m - matrix(runif(150, 0, 1050),

Re: [R] How do I write a sum of matrixes??

2008-05-06 Thread Richard . Cotton
I am a new user and I have been struggling for hours. So finally I decide to ask you: If I have a matrix P, and P.2 = P%*%P, and P.3=P.2%*%P is there a function to calculate the power of a matrix?? if not how can i do: for (i in 1:10) {P.i=P^i} after this I need to sum them up and my

[R] Spacing between lattice panels

2008-05-06 Thread Richard . Cotton
I'm trying to set up a lattice plot with two y-axes for each panel. (Yes, I know that multiple y-axes are generally a bad idea; the graph is for someone else and they want it that way.) I've used a custom yscale.component in xyplot to achieve this: myyscale.component - function(...) { ans

Re: [R] i-best, grep function

2008-05-07 Thread Richard . Cotton
T1 - read.delim(file=S://SEDIM//Yvonne//2_5//T1.txt,col.names= c(Dye/Sample_Peak, Sample_File_Name, Size, Height, Area_in_Point, Area_in_BP, Data_Point, Begin_Point, Begin_BP, End_Point, End_BP, Width_in_Point, Width_in_BP, User_Comments, User_Edit)) T1 - subset(T1, Size 1000 Size 50)

Re: [R] Cumulative lattice histograms

2008-05-12 Thread Richard . Cotton
It's fairly straightforward to plot cumulative histograms using the hist() function. You do something like: h - hist(rnorm(100), plot=FALSE) h$counts- cumsum(h$counts) plot(h) However, I have failed to find any example where this is done using the lattice histogram() function. I

Re: [R] inserting mathematical symbols in lattice strip

2008-05-12 Thread Richard . Cotton
I have tried without success to find a way including the square root symbol in lattice strips as part of my conditioning labels. I have tried supplementing by creating a list of vectors using the var.name function coupled with the expression function used in xlab/ylab.

Re: [R] Regular Expressions

2008-05-13 Thread Richard . Cotton
S=c(World_is_beautiful, one_two_three_four,My_book) I need to extract the last but one element of the strings. So, my output should look like: Ans=c(is,three,My) gsub() can do this...but wondering how do I give the regular expression sapply(strsplit(S, _), function(x)

Re: [R] Left censored responses in mixed effects models

2008-05-13 Thread Richard Cotton
Bert Gunter wrote: What is your recommended way of dealing with a left-censored response (non-detects) in (linear Gaussian) mixed effects models? Specifics: Response is a numeric positive measurement (of volume, actually); but when it falls below some unknown and slightly random value

Re: [R] add horizontal line (ABLINE(V=)) to xyplot lattice

2008-05-13 Thread Richard . Cotton
In a lattice plot like this: win.graph() xyplot(tmx~frequ|as.factor(as.numeric(spf)),groups=as.factor(blm), data=tmx,type=l,pch=16,xlab=frequency (N),ylab=Area held (ha), auto.key=list(blm,points=F,lines=T,title=Blm factor,cex.title=0.7, cex=0.7,corner=c(1,1)),main=Mangroves

Re: [R] Function for subset of cases/lines

2008-05-15 Thread Richard . Cotton
I have a vector: q1-c(4660,5621,5629,8030,8080,8180,8501,8190,8370,8200) The following command gives me the mean of its elements: mean(q1) [1] 7346.1 What can I do to do the same for the variable 'height', but only for the cases/rows which have one of the elements of q1 as

Re: [R] How to swap and rearrange rows?

2008-05-16 Thread Richard . Cotton
How to swap and rearrange the row so that I will have Jan-Dec in order? est31 p0 est.alpha est.beta est.rate Jan 0.8802867 0.7321440 7.241757 0.1380880 Mar 0.8598566 0.7096567 7.376367 0.1355681 May 0.6204301 0.8657272 6.036106 0.1656697 July 0.5032258 0.9928488 4.027408

Re: [R] Kappa distribution

2008-05-29 Thread Richard . Cotton
I am looking for an R implementation of the four parameter kappa distribution (cdf, pdf, quantile, and ransom numbers), or at a minimum, the generalized logistic distribution. I searched for kappa distribution on Rseek (http://www.rseek.org) and the functions you want appear to be in the

Re: [R] Plotting a cubic line from a multiple regression

2008-05-29 Thread Richard . Cotton
I'm attempting to plot a cubic relationship between two variables controlling for the effects of a third variable. In this short example, I'm trying to use AGE to predict CORTEX while controlling for the effects of TIV (total intracranial volume): cortex =

Re: [R] On reading posts on this list

2008-05-29 Thread Richard . Cotton
I am fairly new to R and this list (this is my first post), so I am wondering whether there is a possibility to view posts on this list conveniently on a website besides reading my email. You can see them on Nabble, but there is a delay of a couple of hours.

Re: [R] apply in apply

2008-05-30 Thread Richard . Cotton
I need to apply a function on each column of each matrix contained in a list. Consider the following code, x - 1:3 my.data - list(matrix(c(1,2,3,4,5,6),ncol=2), matrix(c(4,5,6,7,8,9),ncol=2)) par(mfrow=c(2,2)) results - sapply(1:length(my.data), function(ii)

Re: [R] Create Pie chart from .csv file

2009-05-05 Thread Richard . Cotton
I am looking to create a pie chart from a given column in a .csv file. My class variables are as follows: entry_type, uniquekey, types, title,url, abstract, journal, author, month, year, howpublished So say I want to export a pie chart that groups together all entries under

Re: [R] Create Pie chart from .csv file

2009-05-07 Thread Richard . Cotton
Ive found out a way around my problem. I was trying to plaot a histogram of strings, but I had to change it into integers. I ran an sql query on the original DB that I got the CSV file from and used COUNT to get the number of each unique item in a given column. I then used these numbers to

Re: [R] Show name of dataset in graph

2009-05-07 Thread Richard . Cotton
I?ve written a script to run several multivariate statistical analysis automatically. As one result a biplot and screeplot is produced. Now I?d like to display the name of the inputdatset as part of the title of these graphics and I do not want to enter it each time I run the script. How

Re: [R] Plotting questions

2009-05-08 Thread Richard . Cotton
1. How to plot several lines in a figure? Suppose I have several sets of points (xi,yi), where xi and yi are equal-length vector. plot(x1,y1) will give a line connecting these points. Another plot(x2,y2) will erase what plot before and plot the new line. Can I have these lines all drawn in

Re: [R] I'm offering $300 for someone who know R-programming to do the assignments for me.

2009-05-08 Thread Richard . Cotton
There are six assignments in total. It won't take you long if you were familiar with R. For those who are interested, please send me an email with your profile (your experience with R, how long and how often have you been using it.) I will be paying through paypal. Thanks! Now see, you made

Re: [R] howto find x value where x=max(x)

2009-05-08 Thread Richard . Cotton
fp is a data frame like this ,[ fp ] |Frequenz AmpNorm | 1 3322 0.0379490639 | 2 3061 0.0476033058 | 3 2833 0.0592954124 | 4 2242 0.1275510204 ` i want to find the Frequenz where AmpNorm is max. Use which.max. fp -

Re: [R] working with groups of labels?

2009-05-11 Thread Richard . Cotton
I have a graph with groups of variables. I have include the group names as variables so that I can have them positioned correctly. Unfortunately this means that the group names have to follow all of the same rules as the variables within the groups. I would rather have those group names

Re: [R] What does it mean by skip=2 and skip=7?

2009-05-11 Thread Richard . Cotton
Can anyone tell me what is skip=2, skip =7 From ?read.csv: skip: integer: the number of lines of the data file to skip before beginning to read data. and %in% mean here? %in% matches values; see ?'%in%', and example('%in%') Regards, Richie. Mathematical Sciences Unit HSL

Re: [R] working with groups of labels?

2009-05-11 Thread Richard . Cotton
It seems that the structure of your data is that you have two groups (Real Bad Stuff and Other Crazy Things) which are then subdivided into further categories. I'd be tempted to set your data up like this: dfr - data.frame( score=c(23, 14, 17, 8, 43, 13), group=rep(c(Real Bad Stuff,

Re: [R] decimal troubles ?

2009-05-12 Thread Richard . Cotton
I have some trouble with the number of decimals in R (currently R 2.9.0). For instance: options()$digits [1] 3 let me hope that I will get three digits where useful when a number is printed. BUT: 44.25+31.1+50 [1] 125 No way to get the right result 125.35 Can anybody tell

Re: [R] (no subject)

2009-05-12 Thread Richard . Cotton
if i have the following function, f - function(x) x^3-2*x^2+3*x-5 i need a simple function for the derivative of this with respect to 'x', so that i can then sub in values to the the derivative function, and use Newtons method of finding a root for this. You could take a look at

Re: [R] lattice histogram for multiple variables : adjusting x axis

2009-05-12 Thread Richard . Cotton
I have a large data frame and I want to look at the distribution of each variable very quickly by plotting an individual histogram for each variable. I'd like to do so using lattice. Here is a small example using the iris data set:

  1   2   3   >