R language assign and get function usage

Source: Internet
Author: User

assign function in the loop, assigning values to variables, it is more convenient1. Assigning values to variables

[Plain]View PlainCopy 
    1. For (I in 1: (Length (ROWSEQ)-1)) {
    2. Assign (Paste ("nginx_server_fields7_", I, Sep = ""), nginx_server_fields7[(rowseq[(i-1) +1]):(rowseq[i+1]),])
    3. }

2. Assigning values to variables A1, A2, and A3 through a for loop

[Plain]View PlainCopy 
    1. For (i in 1:3) {
    2. Assign (Paste ("a", I, Sep = ""), I:10)
    3. }
    4. LS ()
    5. [1] "A1" "A2" "A3" "I"
    6. > A1
    7. [1] 1 2 3 4 5 6 7 8 9 10
    8. > A2
    9. [1] 2 3 4 5 6 7 8 9 10

3. Get and assign Union usage

[Plain]View PlainCopy 
      1. RM (list = ls ()) #这个命令千万慎重使用
      2. For (i in 1:3) {
      3. Assign (Paste ("P", I, sep= ""), I)
      4. TMP <-Get (Paste ("P", I, sep= ""))
      5. Print (TMP)
      6. }
      7. [1] 1
      8. [1] 2
      9. [1] 3
      10. LS ()
      11. [1] "I" "P1" "P2" "P3" "TMP"

R language assign and get function usage

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.