I'd like to make all values that appear more than 10 times from 2D array a random. How should I describe them?I want to do it without looping.
For writing using the for statement,
for(time in unique(a)){
if(length(a[a==time])>=10){
a[a==time]<-0
}
}
I think I can write like that, but I don't know how to make it happen without using a loop.The work we're doing now involves a large number of two-dimensional arrays, so we're looking for ways to achieve this without looping as much as possible.
If you are familiar with the description of R, please take care of it.
The following is how to use the table
function:
f<-as.data.frame(table(a))
a [a% in %f [f$Freq>=10,]$a] <-0
You can use the table
function to obtain the frequency at which unique elements appear.
© 2024 OneMinuteCode. All rights reserved.