Dear R users, Here is a couple a quick questions, for which I was unable to not find any answer in the list archives and in the help: 1- Is there any R equivalents of the VB functions Cint, CStr, etc... (for non VB users, these functions transform the category of a specified variable and smartly adapt the value of this variable) ? I have tried to use the as.numeric, as.factor and as.vector commands but the result is not exactly what I want ([1] 1, 3, 5, 6) >a<-as.factor(cbind(1,3,5,6)) # creates a dummy factor >a [1] 1 3 5 6 Levels: 1 3 5 6 >> a<-as.vector(as.numeric(a)) > a [1] 1 2 3 4 2- When a log scale is called in a graph, the label takes a format like 10^n. Is there a way to come back to a regular number format like 1, 10, 100... without having to create a custom axis ? 3- In lattice graphics, how does the default value of the "axs" argument influence the values of "limits" ? This question should be considered in the following context. The help states that a 4% extension is applied by default to the axis range in base graphics. So, I have tried to apply this 4 % extension to create some custom lattice graphics. I worked on a dataset in which the independent variable ranged from 0 to 120, so I basically customized my axis using limits=c(-4.8,124.8). The results of the graphics with and without the limits command were not identical... Thanks in advance for your help. Sebastien
At 8:45 AM -0400 7/7/07, S?bastien wrote:>Dear R users, > >Here is a couple a quick questions, for which I was unable to not find >any answer in the list archives and in the help: > >1- Is there any R equivalents of the VB functions Cint, CStr, etc... >(for non VB users, these functions transform the category of a specified >variable and smartly adapt the value of this variable) ? > >I have tried to use the as.numeric, as.factor and as.vector commands but >the result is not exactly what I want ([1] 1, 3, 5, 6) > >a<-as.factor(cbind(1,3,5,6)) # creates a dummy factor > >a >[1] 1 3 5 6 >Levels: 1 3 5 6 > >> a<-as.vector(as.numeric(a)) > > a >[1] 1 2 3 4 >Does this give what you want?> a <- factor(c(1,3,5,6)) > a[1] 1 3 5 6 Levels: 1 3 5 6> as.numeric(format(a))[1] 1 3 5 6> as.numeric(as.character(a)) ## an alternative[1] 1 3 5 6><--- remainder omitted --->>Thanks in advance for your help. > >Sebastien >-- --------------------------------- Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 macq at llnl.gov
On 7/7/07, S?bastien <pomchip at free.fr> wrote:> Dear R users, > > Here is a couple a quick questions, for which I was unable to not find > any answer in the list archives and in the help:[...]> 2- When a log scale is called in a graph, the label takes a format like > 10^n.That's true for lattice, but not traditional graphics, as far as I know.> Is there a way to come back to a regular number format like 1, 10, > 100... without having to create a custom axis ?Depends on what you mean by "custom axis". You don't need to manually choose the tick positions etc, but you still need to define the rules that determine how they are calculated. See example(axis.default) for an example where the tick positions remain the same (as the defaults), but the labels change. The slightly different rule used in traditional graphics is available through the axTicks() function, which basically boils down to this: logTicks <- function (lim, loc = c(1, 5)) { ii <- floor(log10(range(lim))) + c(-1, 2) main <- 10^(ii[1]:ii[2]) r <- as.numeric(outer(loc, main, "*")) r[lim[1] <= r & r <= lim[2]] } where 'lim' is the limits in the original scale. So we have> logTicks(c(1, 100))[1] 1 5 10 50 100> logTicks(c(1, 100), loc = c(2, 5, 10))[1] 1 2 5 10 20 50 100> 3- In lattice graphics, how does the default value of the "axs" argument > influence the values of "limits" ? > This question should be considered in the following context. The help > states that a 4% extension is applied by default to the axis range in > base graphics. So, I have tried to apply this 4 % extension to create > some custom lattice graphics. I worked on a dataset in which the > independent variable ranged from 0 to 120, so I basically customized my > axis using limits=c(-4.8,124.8). The results of the graphics with and > without the limits command were not identical...The extension is user-settable in lattice, and defaults to 7% (I think this value came from Trellis specs, but I don't remember the exact details).> lattice.getOption("axis.padding")$numeric [1] 0.07 $factor [1] 0.6 -Deepayan