Renaming levels

23 views
Skip to first unread message

ssyl

unread,
Apr 2, 2016, 11:50:56 PM4/2/16
to manipulatr
I am new to the R and just stated to learn

I want to edit my levels in R but not able to figure out how to do it.

actually i have two levels in factor "Irrigation"; one is "Rainfed" and another is"Irrigated".

while entering the data  "Rainfed" has become "rainfed". so R is showing three levels as "rainfed","Rainfed" and "Irrigated".

How to correct it in R?

Jaime Ashander

unread,
Apr 3, 2016, 12:37:50 AM4/3/16
to ssyl, manipulatr
Welcome to R! ThIs list isn't the best place to ask general questions when learning the language.  Try googling first ( edit levels R returns some useful links, including those listed below). If that doesn't work, post a question in the R tag of stack overflow http://stackoverflow.com/tags/r/info This will get you an answer faster. 

All that said, for your problem try: 

levels(d)[levels(d) == 'rainfed'] <- 'Rainfed' # if your data is in d

Some resources:
--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.

Greg Snow

unread,
Apr 4, 2016, 5:10:06 PM4/4/16
to ssyl, manipulatr
If your factor is in a variable named "source" then first run the command:

dput(levels(source))

and you should see something like:

c("Irrigation", "Rainfed", "rainfed")

(though the exact result will depend on your system)

now you can copy, paste, and edit to get this command:

levels(source) <- c("Irrigation", "Rainfed", "Rainfed")

when you run this command (or the correct version for your system, the
order needs to match) it will change your source factor to have the
appropriate 2 levels.
> --
> You received this message because you are subscribed to the Google Groups
> "manipulatr" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to manipulatr+...@googlegroups.com.
> To post to this group, send email to manip...@googlegroups.com.
> Visit this group at https://groups.google.com/group/manipulatr.
> For more options, visit https://groups.google.com/d/optout.



--
Gregory (Greg) L. Snow Ph.D.
538...@gmail.com
Reply all
Reply to author
Forward
0 new messages