R-listers, I'm working on a project where I need to get the lowercase of the county variable in a dataset alike to the example below (only difference is that the full dataset has all the states and counties in the southeast United States). I keep getting this strange error with the lowerize function (which didn't occur the first few times I use the code below), and oddly enough the error doesn't happen with the function CapLeading (which is in the same package).> correlfile[1:3,]state statecounty county 1 AL AL_AUTAUGA AUTAUGA 2 AL AL_BALDWIN BALDWIN 3 AL AL_BARBOUR BARBOUR library(cwhmisc)>correlfile$county[correlfile$state=="AL"]=lowerize(correlfile$county[correlfile$state=="AL"]) Error in get(as.character(FUN), mode = "function", envir = envir) : object 'f' of mode 'function' was not found>correlfile$county[correlfile$state=="AL"]=CapLeading(correlfile$county[correlfile$state=="AL"]) System specs involved R version 2.9.2 cwhmisc package version 2.1 OS - Redhat Enterprise Linux version 5.5 Another strange thing that seems to happen is that when I open R in a different working directory of the server, the lowerize function works without giving this error, for a short while. Before long, it begins giving the aforementioned error message again. I haven't found anything in the archives on this so I turn to the R-listers. Any ideas on why this keeps happening would be very helpful! Thanks! Adrienne Wootten Graduate Research Assistant State Climate Office of North Carolina North Carolina State University [[alternative HTML version deleted]]
On Sep 21, 2010, at 10:11 PM, Adrienne Wootten wrote:> R-listers, > > I'm working on a project where I need to get the lowercase of the > county > variable in a dataset alike to the example below (only difference is > that > the full dataset has all the states and counties in the southeast > United > States). I keep getting this strange error with the lowerize function > (which didn't occur the first few times I use the code below), and > oddly > enough the error doesn't happen with the function CapLeading (which > is in > the same package). > >> correlfile[1:3,] > state statecounty county > 1 AL AL_AUTAUGA AUTAUGA > 2 AL AL_BALDWIN BALDWIN > 3 AL AL_BARBOUR BARBOUR > > library(cwhmisc)On the basis of my initial testing I suspect that these are character vectors rather than factors. If you could produce the results of dput on a larger number of rows it might be helpful. Another thought would be to replace the "=" operator with "<-" The "=" behavior can occasionally be unpredictable. (I repeated the operation of the rhs of that assignment 1000 times inside a replicate call and did not trigger an error with that tiny dataset after reading it in with stringsAsFactors =FALSE. I also wonder why it was necessary to make a new function that does the same thing as the tolower() function, and I wonder if you might substitute a base function for this flakey function? traceback immediately after the error might also be informative. R 2.9 is getting pretty old (2 years?) and you should check to see if upgrading to a current version of R and cwhmisc will solve the problem. (We are getting ready for R 2.12 at this point.) -- David.>> > correlfile$county[correlfile$state=="AL"]=lowerize(correlfile > $county[correlfile$state=="AL"]) > > Error in get(as.character(FUN), mode = "function", envir = envir) : > object 'f' of mode 'function' was not found > >> > correlfile$county[correlfile$state=="AL"]=CapLeading(correlfile > $county[correlfile$state=="AL"]) > > System specs involved > R version 2.9.2 > cwhmisc package version 2.1 > OS - Redhat Enterprise Linux version 5.5 > > Another strange thing that seems to happen is that when I open R in a > different working directory of the server, the lowerize function works > without giving this error, for a short while. Before long, it > begins giving > the aforementioned error message again. > > I haven't found anything in the archives on this so I turn to the R- > listers. > > Any ideas on why this keeps happening would be very helpful! > Thanks! > > > Adrienne Wootten > Graduate Research Assistant > State Climate Office of North Carolina > North Carolina State University > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.
Hi:
It's not hard to roll your own here. For first character capitalization,
mycap <- function(str) {
x <- substring(toupper(str), 1, 1)
y <- substring(tolower(str), 2, nchar(str))
paste(x, y, sep = '')
}
It's not especially fast but it works if the objective is to capitalize only
the first letter of a word.
# Applying this to the best actor in one of my favorite films, Little Big
Man
# (first one I thought of with three names :)
u <- c('cHieF', 'DaN', 'GeORgE')
mycap(u)
[1] "Chief" "Dan" "George"
and on your counties,
with(correlfile, mycap(county))
[1] "Autauga" "Baldwin" "Barbour"
CapLeading on my actor name vector:
library(cwhmisc)
CapLeading(u)
[1] "CHieF" "DaN" "GeORgE"
If you look carefully, the function capitalizes the first letter but leaves
the others as is. I suspect that's not what you expected.
HTH,
Dennis
On Tue, Sep 21, 2010 at 7:11 PM, Adrienne Wootten <amwootte@ncsu.edu>
wrote:
> R-listers,
>
> I'm working on a project where I need to get the lowercase of the
county
> variable in a dataset alike to the example below (only difference is that
> the full dataset has all the states and counties in the southeast United
> States). I keep getting this strange error with the lowerize function
> (which didn't occur the first few times I use the code below), and
oddly
> enough the error doesn't happen with the function CapLeading (which is
in
> the same package).
>
> > correlfile[1:3,]
> state statecounty county
> 1 AL AL_AUTAUGA AUTAUGA
> 2 AL AL_BALDWIN BALDWIN
> 3 AL AL_BARBOUR BARBOUR
>
> library(cwhmisc)
> >
>
>
correlfile$county[correlfile$state=="AL"]=lowerize(correlfile$county[correlfile$state=="AL"])
>
> Error in get(as.character(FUN), mode = "function", envir = envir)
:
> object 'f' of mode 'function' was not found
>
> >
>
>
correlfile$county[correlfile$state=="AL"]=CapLeading(correlfile$county[correlfile$state=="AL"])
>
> System specs involved
> R version 2.9.2
> cwhmisc package version 2.1
> OS - Redhat Enterprise Linux version 5.5
>
> Another strange thing that seems to happen is that when I open R in a
> different working directory of the server, the lowerize function works
> without giving this error, for a short while. Before long, it begins
> giving
> the aforementioned error message again.
>
> I haven't found anything in the archives on this so I turn to the
> R-listers.
>
> Any ideas on why this keeps happening would be very helpful!
> Thanks!
>
>
> Adrienne Wootten
> Graduate Research Assistant
> State Climate Office of North Carolina
> North Carolina State University
>
> [[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]]