[R] [External] categorizing data
Richard M. Heiberger
rmh @end|ng |rom temp|e@edu
Sun May 29 21:51:19 CEST 2022
Orig <- read.table(text="
tree shrub grass
32 11 47
23 41 26
49 23 18
", header=TRUE)
New <- Orig
for (i in seq(nrow(Orig)))
New[i,] <- c(10, 30, 50)[order(unlist(Orig[i,]))]
New
> On May 29, 2022, at 15:28, Janet Choate <jsc.eco using gmail.com> wrote:
>
> Hi R community,
> I have a data frame with three variables, where each row adds up to 90.
> I want to assign a category of low, medium, or high to the values in each
> row - where the lowest value per row will be set to 10, the medium value
> set to 30, and the high value set to 50 - so each row still adds up to 90.
>
> For example:
> Data: Orig
> tree shrub grass
> 32 11 47
> 23 41 26
> 49 23 18
>
> Data: New
> tree shrub grass
> 30 10 50
> 10 50 30
> 50 30 10
>
> I am not attaching any code here as I have not been able to write anything
> effective! appreciate help with this!
> thank you,
> JC
>
> --
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Crmh%40temple.edu%7C165bca7d509542fc339d08da41a98821%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637894493792524879%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=ZxDMzULApfm9p%2BnnXhToAfvFNZx7du6e%2BbqoaNc6iYE%3D&reserved=0
> PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Crmh%40temple.edu%7C165bca7d509542fc339d08da41a98821%7C716e81efb52244738e3110bd02ccf6e5%7C0%7C0%7C637894493792524879%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=oVJe7FTikuD7Y59kbg9O1k4od357HPwTcylhTn6ZLWw%3D&reserved=0
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list