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

Rui Barradas ru|pb@rr@d@@ @end|ng |rom @@po@pt
Mon Jan 17 20:50:45 CET 2022


Hello,

I agree with everybody else, tyhis is a bad idea but I don't understand 
what you mean by you first categorized continuous data and now you want 
continuous data out of categorical one. Don't you still have the 
original data? If yes, why not that one.


If it's just the midpoints, something like


x <- sub("^\\(", "", daT$group)
y <- sub("\\]$", "", x)
sapply(strsplit(y, ","), \(.y){
   diff(as.numeric(.y))/2
})
# [1] 0.0050 0.0075 0.0125 0.0125 0.0125 0.0500 0.0500 0.0500
# [9] 0.0500 0.0500 0.0500 0.0500 0.0500 0.0500 0.0500 0.2000
#[17] 0.2500 0.2500


Hope this helps,

Rui Barradas

Às 18:35 de 17/01/22, peter dalgaard escreveu:
> 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.
>



More information about the R-help mailing list