Question

R programming: provide code and explanation

b. -Heres an integer vector . what happens if you ins ert NULL into the 4th position of the vector ?- irJ a <-1:10 print (a)

16. -what is the difference between the assignment operators 、<-. and 、<<-.? Look up helpCassignops),15. -Can you have a data frame with 0 rows? what about 0 columns? If it is possible, write some code to create such a data. frame._ write your answer here.

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

b.

If we try to insert NULL value to the 4th position in the vector, we get an error.

> a<-1:10
> a[4] <- NULL
Error in a[4] <- NULL : replacement has length zero

NULL is a zero length special object in R. We cannot assign this object to a specific element of a vector object in R. You may however assign it to the vector object itself.

16.

<- operator is used to assign variable in the same environment

<<- operator is used to assign variable in the global environment

For e.g.

Using the global environment assignment operator

> x <<- 10

Below is a function which assigns value to x in its local environment using <- operator

> test <- function(y) {x<- y
+ print(x)}
> test(2)
[1] 2

Now if we print x, the value from the global environment would be printed.

> print(x)
[1] 10

15. Yes we can have a data frame with 0 rows and 0 columns.

> df <-data.frame()
> df
data frame with 0 columns and 0 rows

Add a comment
Know the answer?
Add Answer to:
R programming: provide code and explanation b. -Here's an integer vector . what happens if you...
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
Active Questions
ADVERTISEMENT