R language Learning (ii)

Source: Internet
Author: User

1. Vector of complex numbers: generating complex vectors with the complex () function

EX:

> X<-seq (-PI,PI,BY=PI/10)%x value

> Y<-sin (x)%y value
> Z<-complex (re=x,im=y)%re as the real part, IM for the complex part

> Plot (z); lines (z)% drawing graphics

Run as follows:

2. Subscript operation of vectors

The R software provides very flexible access to vector elements and functions to the quantum set, and an element of the x vector can be accessed in the X[i] format

EX:

> x<-c (1,4,7)
> X[2]
[1] 4
> (c (1,3,5) +5) [2]
[1] 8

You can change the value of an element individually

> x[2]<-125
> x
[1] 1 125 7
> x[c (1,3)]<-c (144,169)
> x
[1] 144 125 169

3. Logical vector

V and x equal-length logical vectors, x[v] represent the removal of all elements of the V as Truth, Ex:

> x<-c (1,4,7)
> x<5
[1] True True FALSE
> X[x<5]
[1] 1 4

Vector missing data can be assigned to 0

EX:

> z<-c ( -1,1:3,na)
> z[is.na (z)]<-0
> Z
[1]-1 1 2 3 0

You can assign the non-missing data in the vector to another vector

EX:

> Y<-z[!is.na (z)]
> y
[1]-1 1 2 3

Do the corresponding calculations

> (z+1) [(!is.na (z)) &z>0]->x
> x
[1] 2 3 4

4. Positive integer operation of subscript

V is a vector, the subscript value between 1 to Length (v), the value allowed to repeat, EX:

V<-10:20

V[c (1,3,5,9)]

[1] 10 12 14 18

5. Negative integer operations on the underlying

V is a vector, the subscript value is between-lenght () and-1, EX:

> v<-10:20
> v[-(1:5)]
[1] 15 16 17 18 19 20

Represents the deduction of the corresponding element

6. Small-scale operation with a character value

> ages<-c (li=33,zhang=29,liu=18)
> Ages
Li Zhang Liu
33 29 18

> ages["Zhang"]
Zhang
29

You can add a name to a vector.

> fruit<-c (5,10,1,20)

> Names (Fruit) <-c ("Orange", "banana", "apple", "peach")
> Fruit
Orange Banana Apple Peach
5 10 1 20

R language Learning (ii)

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.