[R] How to convert category (or range/group) into continuous ?

peter dalgaard pd@|gd @end|ng |rom gm@||@com
Mon Jan 17 19:35:34 CET 2022


Depends on what was meant. If you just want the interval midpoints for plotting, you can do something like

endp <- c(0,.01, .025, .05, ... 2.5) # some manual assembly required here
mid <- (head(endp, -1) + tail(endp, -1))/2
groupmid <- mid[group]
plot(groupmid, VALUE)

-pd

> On 17 Jan 2022, at 16:34 , Bert Gunter <bgunter.4567 using gmail.com> wrote:
> 
> IMO, this is a bad idea. You are asking how to fabricate information that
> isn't there. You lost the information when you created the categories. Why
> can you not just go back to your original data?
> 
> Bert Gunter
> 
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> 
> 
> On Sun, Jan 16, 2022 at 11:06 PM Marna Wagley <marna.wagley using gmail.com>
> wrote:
> 
>> Hi R users,
>> I first categorized the continuous data into groups (ranges or category)
>> but now I would like to change the category into a continuous data and
>> plot it. For example I have attached the data in which you can see two
>> columns named "group" and "value". The group column contains a range
>> (group, for example ), I am wondering how I can change the category data
>> (for example: "0,0.01]" )into continuous data with a 0.1 interval.
>> Thank you for your suggestions.
>> 
>> daT<-structure(list(group = c("(0,0.01]", "(0.01,0.025]", "(0.025,0.05]",
>> "(0.05,0.075]", "(0.075,0.1]", "(0.1,0.2]", "(0.2,0.3]", "(0.3,0.4]",
>> "(0.4,0.5]", "(0.5,0.6]", "(0.6,0.7]", "(0.7,0.8]", "(0.8,0.9]",
>> "(0.9,1]", "(1,1.1]", "(1.1,1.5]", "(1.5,2]", "(2,2.5]"), VALUE = c(1,
>> 1, 1, 1, 1, 1, 0.944444444, 0.916666667, 0.888888889, 0.857777778,
>> 0.826666667, 0.66, 0.439090909, 0.328636364, 0.273409091, 0.245795455,
>> 0.218181818, 0.084848485)), class = "data.frame", row.names = c(NA,
>> -18L))
>> thanks,
>> MW
>> 
>>        [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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]]
> 
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes using cbs.dk  Priv: PDalgd using gmail.com



More information about the R-help mailing list