How to exclude observations and variables in an array in R?

2

The situation is as follows: I have an array with 271 observations and 14 variables in R. I need to randomly exclude a number of crosses and variables, keeping the order of the remaining crosses and adding NA's at the excluded crosses.

At the moment, I can randomly delete and replace the comments ("rows") using the following code:

X100amostra <- X100[sample(1:nrow(X100), 50,
   replace=TRUE),]

where "50" is the number of random deletions.

Still, I can do deletions in the form of vectors. I'd like to do it in array form.

Any suggestions?

    
asked by anonymous 19.03.2017 / 00:45

1 answer

1

See if this is what you want:

matriz<- matrix(1:3794,ncol=14) # Cria uma matriz qualquer 271x14
matriz[sample(1:length(matriz),50,replace=FALSE)]<-NA # Substitui 50 valores por NA aleatoriamente
    
19.03.2017 / 10:43