Skip to content
Prev 385834 / 398503 Next

how to turn column into column names and fill it with values

You should be able to figure this out yourself!

The number of new columns you add **must agree with the number of unique
id's PLATE** !

Here is the general approach, slightly more efficient, probably:

PL = dat$PLATE
nm<- unique(PL)
len <- length(nm)
m <- matrix(0, ncol = len, nrow = nrow(dat), dimnames = list(NULL, nm))
for(i in 1:len) m[,i] <- 1 + (nm[i] == PL)
dat <- cbind(dat, m)

This code works. If you change it, don't ask me to account for errors.

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 Tue, Sep 29, 2020 at 10:08 AM Ana Marija <sokovic.anamarija at gmail.com>
wrote: