Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)
edited by

I have a column in a data frame that looks like the following:

pscore  pscoreblocks

0.18    (.177, 0.187)

0.24    (0.237, 0.246)

0.07    (0.069, 0.079)

I have added the pscoreblocks column by dividing the pscore column into 100 evenly spaced intervals.

dfc$pscoreblocks <- cut_interval(dfc$pscore, n=100)

I want to have a new set of the column with a different number for each of the 100 intervals, how can I do that?

pscore  pscoreblocks    block_number

0.18    (.177, 0.187)   3

0.24    (0.237, 0.246)  5

0.07    (0.069, 0.079)  1

1 Answer

0 votes
by (108k points)

Just convert pscoreblocks to an integer with the help of following code:

dfc$block_number <- as.integer(dfc$pscoreblocks)

You can also use a match() and unique() as follows:

dfc$block_number <- match(dfc$pscoreblocks, unique(dfc$pscoreblocks))

If you are a beginner and want to know more about R then do check out the R programming tutorial

Browse Categories

...