Back

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

I am exploring for a series of values that could be existing in any of 9 potential columns, and they all actually represent the same thing, so I want to dichotomize those 9 columns into one for analysis.

    embolization = c("37200", "37211", "37213", "37214", "37236", "37237", "37238", "37239", "37241", "37242", "37243", "37244", "61624", "61626")

    embolization <- as.list(embolization)

    f = function(x) any(x == embolization, na.rm = FALSE)

apply(df2, MARGIN = 1, FUN = f)

When I executed the above function I am getting an error saying longer object length is not a multiple of the shorter object. 

The data frame is as follows:

     CPT1    CPT2    CPT3

1   49205   44015   38747

2   44015   38747   NULL

3   44015   38747   NULL

4   31624   NULL    NULL

5   NULL    NULL    NULL

6   43621   38747   44015

7   NULL    NULL    NULL

And from that, let's say I want any of the values (38747, 30984, and 34445) to end up as a new column to be true. The desired output is:

     CPT1    CPT2    CPT3  newcol

1   49205   44015   38747  TRUE

2   44015   38747   NULL   TRUE

3   44015   38747   NULL   TRUE

4   31624   NULL    NULL   FALSE

5   NULL    NULL    NULL   FALSE

6   43621   38747   44015  TRUE

7   NULL    NULL    NULL   FALSE

Please log in or register to answer this question.

Browse Categories

...