Question

Using the R language: Suppose we have a vector, called longvector with 1000 elements. A. How...

Using the R language:

Suppose we have a vector, called longvector with 1000 elements. A. How would you let R calculate the mean value of longvector? Write the code here:

B. What if there are some NA values and you'd like R to remove the NA values when calculating the mean of longvector? Write the code here:

C. How would you plot a histogram to show the distribution of values in longvector? Write the code here:

D. How would you sample a random element from longvector? Write the code here:

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution: A) #Declare vect r longvector <1:1000; #calculate mean mean (longvector) Output: 4.3s Rscript main.r [1] 500.5 B) #

Histogram of longvector 20 40 60 80 100 longvector D) #Declare vector with random values longvector <- runif (n-1000,min-1,ma

Code:

A)

#Declare vector

longvector <- 1:1000;

#calculate mean

mean(longvector)

B)

#Declare vector

longvector <- 1:1000;

#Last value made as NA

longvector[1000]=NA

#Calculate mean

mean(longvector,na.rm=TRUE)

C)

#Declare vector with random values

longvector <- runif(n=1000,min=1,max=100)

#histogram of longvector

hist(longvector)

#Declare vector with random values

longvector <- runif(n=1000,min=1,max=100)

#sample a random element

sample(longvector,1)

Add a comment
Know the answer?
Add Answer to:
Using the R language: Suppose we have a vector, called longvector with 1000 elements. A. How...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT