Turn on thread page Beta
    • Thread Starter
    Offline

    9
    ReputationRep:
    Hello, I really need some help with this. Whatever I do I cannot get the R code to do what I want.

    The problem is,

    "In the box below, write some code that will construct a vector x of the integers from 1 to 100, and then replace the first 10 elements of x with missing values. Make sure that the last line of your code contains just x (by itself). This is for grading purposes".

    First off I am a complete novice with using R as I am a Maths student and we need to learn how to use it for part of the course. I've been okay up until now but I can't get work out what to do.

    I've tried

    c((x=1:100),(x[1:10]=NA)) but I don't think this is correct.

    Any help would be amazing. Also if you could show me some useful websites I could use to learn how to use R more effectively.
    • Thread Starter
    Offline

    9
    ReputationRep:
    Anyone??
    • Very Important Poster
    Offline

    21
    ReputationRep:
    Very Important Poster
    (Original post by Mr XcX)
    Hello, I really need some help with this. Whatever I do I cannot get the R code to do what I want.

    The problem is,

    "In the box below, write some code that will construct a vector x of the integers from 1 to 100, and then replace the first 10 elements of x with missing values. Make sure that the last line of your code contains just x (by itself). This is for grading purposes".

    First off I am a complete novice with using R as I am a Maths student and we need to learn how to use it for part of the course. I've been okay up until now but I can't get work out what to do.

    I've tried

    c((x=1:100),(x[1:10]=NA)) but I don't think this is correct.

    Any help would be amazing. Also if you could show me some useful websites I could use to learn how to use R more effectively.
    'Missing values' sounds very ambiguous to me. But with your code and the x on the last line, putting that into R seems to give a reasonable output. I'm not sure what more they want.

    For R, google is your friend - typing in questions will help. In R, you can also type in help(insert name of function here) and it'll bring up a page describing what the function does, what its inputs are etc.
    • Thread Starter
    Offline

    9
    ReputationRep:
    (Original post by SeanFM)
    'Missing values' sounds very ambiguous to me. But with your code and the x on the last line, putting that into R seems to give a reasonable output. I'm not sure what more they want.

    For R, google is your friend - typing in questions will help. In R, you can also type in help(insert name of function here) and it'll bring up a page describing what the function does, what its inputs are etc.
    Thank you for responding.

    I'll try google tomorrow for more help on R I have a while before this is due.

    So should I put my code as this,

    c((x=1:100),(x[1:10]=NA)) x

    with the x at the end. The wording is really confusing.
    • Thread Starter
    Offline

    9
    ReputationRep:
    When I input the code I get,

    c((x=1:100),(x[1:10]=NA))
    [1] NA NA NA NA NA NA NA NA NA NA 11 12 13 14 15 16 17 18
    [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    [91] 91 92 93 94 95 96 97 98 99 100 NA

    I don't understand where this NA is coming from at the end?
    • Very Important Poster
    Offline

    21
    ReputationRep:
    Very Important Poster
    (Original post by Mr XcX)
    Thank you for responding.

    I'll try google tomorrow for more help on R I have a while before this is due.

    So should I put my code as this,

    c((x=1:100),(x[1:10]=NA)) x

    with the x at the end. The wording is really confusing.
    Yes, the wording is quite confusing.

    It may be a good idea to have x on a seperate line, as typing that into one line on R won't work (as it won't know what to do inbetween the created vector and the x).
    • Very Important Poster
    Offline

    21
    ReputationRep:
    Very Important Poster
    (Original post by Mr XcX)
    When I input the code I get,

    c((x=1:100),(x[1:10]=NA))
    [1] NA NA NA NA NA NA NA NA NA NA 11 12 13 14 15 16 17 18
    [19] 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
    [37] 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
    [55] 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
    [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    [91] 91 92 93 94 95 96 97 98 99 100 NA

    I don't understand where this NA is coming from at the end?
    Hm, I didn't originally spot that but right you are.

    From the code you've created I don't understand why a 101st element is created and why it is NA. :dontknow:

    If you create the vector in a slightly different way it doesn't get that problem, for whatever reason.
    Spoiler:
    Show
    x=c(1:100) #which means creating a vector with the numbers from 1 to 100 in it
    x[1:10] = NA #NA is assigned to those elements
    x #returns x
    • Thread Starter
    Offline

    9
    ReputationRep:
    (Original post by SeanFM)
    Yes, the wording is quite confusing.

    It may be a good idea to have x on a seperate line, as typing that into one line on R won't work (as it won't know what to do inbetween the created vector and the x).
    Thank you for helping me. I'll try that.
    • Very Important Poster
    Offline

    21
    ReputationRep:
    Very Important Poster
    (Original post by Mr XcX)
    Thank you for helping me. I'll try that.
    I just saw your reply - see the post above
    • Thread Starter
    Offline

    9
    ReputationRep:
    (Original post by SeanFM)
    Hm, I didn't originally spot that but right you are.

    From the code you've created I don't understand why a 101st element is created and why it is NA. :dontknow:

    If you create the vector in a slightly different way it doesn't get that problem, for whatever reason.
    Spoiler:
    Show
    x=c(1:100) #which means creating a vector with the numbers from 1 to 100 in it
    x[1:10] = NA #NA is assigned to those elements
    x #returns x
    I posted the code like this like you suggested, with the x on a separate line

    c((x=1:100),(x[1:10]=NA))
    x

    and the NA 101'st value disappeared. We're using some software called Rteacher (not sure if you're familiar with it) to learn us how to use R and answer probability and stat questions. It's been glitchy as anything so would not surprise me if having the x on a separate line changed the vector.
    • Very Important Poster
    Offline

    21
    ReputationRep:
    Very Important Poster
    (Original post by Mr XcX)
    I posted the code like this like you suggested, with the x on a separate line

    c((x=1:100),(x[1:10]=NA))
    x

    and the NA 101'st value disappeared. We're using some software called Rteacher (not sure if you're familiar with it) to learn us how to use R and answer probability and stat questions. It's been glitchy as anything so would not surprise me if having the x on a separate line changed the vector.
    I am using the regular version of R (I also have access to Rstudio but I'm not a huge fan of it) and I also got that error, maybe one day we'll know what it is as Maths students

    But I'm glad that it's cleared up for you.
    • Thread Starter
    Offline

    9
    ReputationRep:
    (Original post by SeanFM)
    I am using the regular version of R (I also have access to Rstudio but I'm not a huge fan of it) and I also got that error, maybe one day we'll know what it is as Maths students

    But I'm glad that it's cleared up for you.
    Yeah, one day hopefully

    Thanks again.
 
 
 
Reply
Submit reply
Turn on thread page Beta
Updated: November 6, 2015
Poll
Do you think parents should charge rent?

The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

Write a reply...
Reply
Hide
Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.