Create an object that contains four words. Use the sample function to sample 1000 of this object

-3

... continuing-Find out how to use the table function to know how many times each word has been drawn.

I created the 4words that are "hi" "hi" "hey" and "hi" but when I tried according to an example I saw on youtube it went wrong because there are no vectors.

creation: pal<-c("oi","ola","hey","hi") sample(pal,1000,replace=TRUE)

Execution:

head(pal) levels(pal)

That's where I got the error because in the example I saw the guy was working with vectors

    
asked by anonymous 16.05.2018 / 21:41

2 answers

3

Look:

 pal <- c("oi","ola","hey","hi")
 > is.factor(c("oi","ola","hey","hi"))
 [1] FALSE
 > is.vector(c("oi","ola","hey","hi"))
 [1] TRUE

So pal is a vector and not a category vector, so levels() does not work.

Simply put ctrl + r in the sample(pal,1000, replace=TRUE) line of your scripts and see what happens.
Force it, we've all been n00bs.

    
16.05.2018 / 23:24
2

Are you sure you've copied the right code? It's not something like:

pal <- c("oi","ola","hey","hi")
palavreado <- sample(pal,1000, replace=TRUE)
table(palavreado)
palavreado
hey  hi  oi ola 
251 245 240 264 
    
16.05.2018 / 23:09