[R] problem with source(), parse() and french colnames
Hello every one Working under Windows Xp in French, and R version 2.4.0 (and : localeToCharset() : ISO8859-1 ) I am trying to source a file with basic commands. source(R files/InputFile Analysis (Calculs et mises à l'échelle - gestion des pb d'unités).r) and it works fine as long as I do not use command like these ones : file_table[[2]]$MES.boue.recirculée.autosurveillance - 1000*file_table[[2]]$MES.boue.recirculée.autosurveillance file_table[[2]]$MES.boue.recirculée.en.continu - 1000*file_table[[2]]$MES.boue.recirculée.en.continu These commands work perfectly when used individually and submitted directly. But when I am sourcing the command file including these lines, I get the following error message : Erreur dans parse(file, n = -1, NULL, ?) : erreur de syntaxe à la ligne 35: MES.liqueur.mixte.en.continu- 1000*file_table[[2]]$MES.liqueur.mixte.en.continu 36: file_table[[2]]$MES.boue.recircul I guess that the problem is coming form the é in my colnames as the following command : file_table[[2]]$MES.liqueur.mixte.autosurveillance- 1000*file_table[[2]]$MES.liqueur.mixte.autosurveillance works fine, even when sourced ... My colnames are make.names() output, and I am wondering how to set up things to allow é in sourced commands (or enventually to transform é in e with mae.names). Does any body know how ? Thanks, and sincerely yours, Pascal Boisson [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] trellis.par.set and grid : how to set by default that I want a grid on my graphes ?
Hello all, I want to draw a grid behind my graphes, using lattice package. I manage to do it with instructions like this one : xyplot(Sepal.Length + Sepal.Width ~ Petal.Length , data = iris, allow.multiple = TRUE, scales = same,type=l, panel = function(...) { panel.grid(h=-1, v= -1) ; panel.superpose(...) } ) I was wondering if there were a way to do it using for example trellis.par.set() to set this by default, like what I do for colors e.g. : trellis.par.set(list(superpose.line = list(col = c( red, yellow, green, blue, purple, orange, black, maroon, pink, cyan, grey, magenta instead of using in each call this log panel = function (...) { } instruction I tried emprirically trellis.par.set(list(grid.pars= list(h = -1, v=-1))) with no success (I am not even sure that this grid.pars is about drawing grids ... but it is the nearest instruction i found in trellis parameters As i am not very confident with this trellis.par.set(), I might have missed something ... I also tried to define a function grid-function(...) { panel.grid(h=-1, v= -1) ; panel.superpose(...) } xyplot(Sepal.Length + Sepal.Width ~ Petal.Length , data = iris, allow.multiple = TRUE, scales = same,type=l, panel = grid() #also tried grid(...) ) but the only result is an arror message with grid() : Erreur dans unit(y0, default.units) : 'x' et 'units' doivent avoir une longueur positive (x and units should have a positive length) with grid(...) : '...' utilisé dans un contexte incorrect ('...' used in a wrong context) Could anyone tell me a way of doing it ? -- Pascal Boisson [EMAIL PROTECTED] http://pak.enroweb.com http://www.flickr.com/photos/hoothootprod/ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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] Reconstruction of a valid expression within a function
Hello all, I have some trouble in reconstructing a valid expression within a function, here is my question. I am building a function : SUB-function(DF,subset=TRUE) { #where DF is a data frame, with Var1, Var2, Fact1, Fact2, Fact3 #and subset would be an expression, eg. Fact3 == 1 #in a first time I want to build a subset from DF #I managed to, with an expression like eg. DF$Fact3, # but I would like to skip the DF$ for convenience # so I tried something like this : tabsub-deparse(substitute(subset)) dDF-deparse(substitute(DF)) if (tabsub[1]!=TRUE) { subset-paste(dDF,$,tabsub,sep=)} #At this point, I have a string that seems to be the expression that I want sDF-subset(DF, subset) } #But I have an error message : Error in r !is.na(r) : operations are possible only for numeric or logical types I can not understand why is that, even after I've tried to convert properly the string into an expression. I've been all the day trying to sort that problem ... Maybe this attempt is ackward and I have not understood what is really behind an expression. But if anyone could give me a tip concerning this problem or point me to relevant references, I would really appreciate. Thanks Pascal Boisson _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ DISCLAIMER:\ \ This email is from the Scottish Crop Researc...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Construction of a mean contengency table
Hi List, Say I have a data.frame DF with 6 columns, 3 factors and 3 variables, with different number of repetitions for each combination of factors. I would like to build, for two given factors, a matrix per variable, containing in each cell the mean or sd for a given couple of factors. I have managed to get to the result I wanted step by step, but I would like to have it in a function. I have not found what I was looking for so I decided to try to write my own function, using aggregate( ) to generate the mean values as a dataframe, and then display this as a matrix. I'd like it to be general enough so that I could use it in many cases. From what I have tried and understood, table( ) cannot do what I want (no mean or sd ...) neither does xtabs( ), i.e. asking for a formula not a function to passed as an argument ... My final aim would be to plot this with persp( ), and it seems that persp( ) must be fed with 2 dimensional arrays ... Below is what I have tried to write, but it is not working. It might be awkward, but I think it can work ... I think it is a problem about correctly receiving and passing arguments in the different function calls. Do you think there would be a smarter way of doing this ? Or can you see what is going wrong with this ? Any advice will be welcome Pascal Boisson matrixation-function(DF, var, factorlist, FUN, condition) ## DF is the original dataframe with raw results from my experiments ## var is the var that I want to print ## eg. DF$var1 ## factorlist is a list of the two factor I want to mean against (but I'm noot sure List is the best form for this argument), ## eg. list(DF$fact1, DF$fact2) ## FUN would be the function I want to use during aggregation, ## eg. Mean( ) ## condition would be a condition for building a subset ## eg. DF$fact3==1 { sDF - subset(DF, condition) A - aggregate(sDF, factorlist, FUN) M - matrix(data=NA, nrow = length(levels(factorlist[[1]])), ncol = length(levels(factorlist[[2]])), dimnames = list(levels(factorlist[[1]]),levels(factorlist[[2]]) ) ) for (i in 1:length(A[,1])) { tPhii - A$Group.1[i] tAppari - A$Group.2[i] M[tPhii, tAppari] - A$pest_max_number[i] } return(M) } _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ DISCLAIMER:\ \ This email is from the Scottish Crop Researc...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html