Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use R language list and data box

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use R language list and data box". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to use R language lists and data boxes.

1. List

List "list" is a special collection of objects for comparison, different sequence numbers for different elements, of course, elements can also be of different types, so we use R language to simply construct a list.

Create > a b mlist mlist [[1] [1] 12 3 4 5 6 7 8 9 10 11 12 13 14 [15] 15 16 17 18 19 20 [[2]] [, 1] [, 2] [, 4] [, 5] [1,] 15 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4] ] 4 8 12 16 201.2 visit

1.2.1 subscript access

> mlist [1] [[1]] [1] 12 3 4 5 6 7 8 9 10 11 13 14 [15] 15 16 17 18 19 20 > mlist [2] [[1]] [, 1] [, 3] [, 4] [, 5] [1,] 15 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4] ] 4 8 12 16 20

1.2.2 name access

> state.center ["x"] $x [1]-86.7509-127.2500-111.6250-92.2992 [5]-119.7730-105.5130-72.3573-74.9841 [9]-81.6850-83.3736-126.2500-113.9300 [13]-89.3776-86.0808-93.3714-98.1156 [17]-84.7674-92.2724-68.9801-76.6459 [21]-71.5800-84.6870-94.6043-89.8065 [25]-92.5137-109.3200-99.5898-116.8510 [29]-71.3924-74.2336-105.9420-75.1449 [33]-78.4686-100.0990-82.5963-97.1239 [37]-120.0680-77.4500-71.1244-80.5056 [41]-99.7238 -86.4560-98.7857-111.3300 [45]-72.5450-78.2005-119.7460-80.6665 [49]-89.9941-107.2560

1.2.3 symbolic access

> state.center$x [1]-86.7509-127.2500-111.6250-92.2992 [5]-119.7730-105.5130-72.3573-74.9841 [9]-81.6850-83.3736-126.2500-113.9300 [13]-89.3776-86.0808-93.3714-98.1156 [17]-84.7674-92.2724-68.9801-76.6459 [21]-71 5800-84.6870-94.6043-89.8065 [25]-92.5137-109.3200-99.5898-116.8510 [29]-71.3924-74.2336-105.9420-75.1449 [33]-78.4686-100.0990-82.5963-97.1239 [37]-120.0680-77.4500-71.1244-80.5056 [41]-99.7238-86.4560- 98.7857-111.3300 [45]-72.5450-78.2005-119.7460-80.6665 [49]-89.9941-107.25601.3 Note

The difference between one square bracket and two square brackets

One square bracket outputs a sublist of the list, and two brackets output the elements of the list.

> class (mlist [1]) [1] "list" > class (mlist [[1]]) [1] "integer"

When we add elements, we should pay attention to using two square brackets

two。 Data frame

The data box is a data structure of R, it is usually data in the form of matrix, but the columns of the matrix can be of different types, each column of the data box is a variable, and no row is an observation.

However, a data box is a special list object whose class attribute is "data.frame". Each list member must be a vector (numeric, character, logical), factor, numeric matrix, list, or other data box. Vector and factor members provide a variable for the data box, and if the vector is non-numerical, it will be strongly converted into a factor. The matrix, list, data box, and so on must have the same number of rows as the data box.

2.1 create > state state state.name state.abb state.area1 Alabama AL 516092 Alaska AK 5897573 Arizona AZ 1139094 Arkansas AR 531045 California CA 1586936 Colorado CO 1042477 Connecticut CT 50098 Delaware DE 20579 Florida FL 5856010 Georgia GA 5887611 Hawaii HI 645012 Idaho ID 8355713 Illinois IL 5640014 Indiana IN 3629115 Iowa IA 5629016 Kansas KS 8226417 Kentucky KY 4039518 Louisiana LA 4852319 Maine ME 3321520 Maryland MD 1057721 Massachusetts MA 825722 Michigan MI 5821623 Minnesota MN 8406824 Mississippi MS 4771625 Missouri MO 6968626 Montana MT 14713827 Nebraska NE 7722728 Nevada NV 11054029 New Hampshire NH 930430 New Jersey NJ 783631 New Mexico NM 12166632 New York NY 4957633 North Carolina NC 5258634 North Dakota ND 7066535 Ohio OH 4122236 Oklahoma OK 6991937 Oregon OR 9698138 Pennsylvania PA 4533339 Rhode Island RI 121440 South Carolina SC 3105541 South Dakota SD 7704742 Tennessee TN 4224443 Texas TX 26733944 Utah UT 8491645 Vermont VT 960946 Virginia VA 4081547 Washington WA 681948 West Virginia WV 2418149 Wisconsin WI 5615450 Wyoming WY 97914 > 2.2 visit

2.2.1 subscript access

> state [1] state.name1 Alabama2 Alaska3 Arizona4 Arkansas5 California6 Colorado7 Connecticut8 Delaware9 Florida10 Georgia11 Hawaii12 Idaho13 Illinois14 Indiana15 Iowa16 Kansas17 Kentucky18 Louisiana19 Maine20 Maryland21 Massachusetts22 Michigan23 Minnesota24 Mississippi25 Missouri26 Montana27 Nebraska28 Nevada29 New Hampshire30 New Jersey31 New Mexico32 New York33 North Carolina34 North Dakota35 Ohio36 Oklahoma37 Oregon38 Pennsylvania39 Rhode Island40 South Carolina41 South Dakota42 Tennessee43 Texas44 Utah45 Vermont46 Virginia47 Washington48 West Virginia49 Wisconsin50 Wyoming

2.2.2 name access

> state ["state.name"] state.name1 Alabama2 Alaska3 Arizona4 Arkansas5 California6 Colorado7 Connecticut8 Delaware9 Florida10 Georgia11 Hawaii12 Idaho13 Illinois14 Indiana15 Iowa16 Kansas17 Kentucky18 Louisiana19 Maine20 Maryland21 Massachusetts22 Michigan23 Minnesota24 Mississippi25 Missouri26 Montana27 Nebraska28 Nevada29 New Hampshire30 New Jersey31 New Mexico32 New York33 North Carolina34 North Dakota35 Ohio36 Oklahoma37 Oregon38 Pennsylvania39 Rhode Island40 South Carolina41 South Dakota42 Tennessee43 Texas44 Utah45 Vermont46 Virginia47 Washington48 West Virginia49 Wisconsin50 Wyoming

2.2.3 symbolic access

> state$state.name [1] "Alabama"Alaska" [3] "Arizona"Arkansas" [5] "California"Colorado" [7] "Connecticut"Delaware" [9] "Florida"Georgia" [11] "Hawaii"Idaho" [13] "Illinois" "Indiana" [15] "Iowa"Kansas" [17] "Kentucky"Louisiana" [19] "Maine"Maryland" [21] "Massachusetts"Michigan" [23] "Minnesota"Mississippi" [25] "Missouri"Montana" [27] "Nebraska" "Nevada" [29] "New Hampshire"New Jersey" [31] "New Mexico"New York" [33] "North Carolina"North Dakota" [35] "Ohio"Oklahoma" [37] "Oregon"Pennsylvania" [39] "Rhode Island"South Carolina" [41] "South Dakota"Tennessee" [43] "Texas", "Utah" [45], "Vermont", "Virginia" [47], "Washington", "West Virginia" [49] "Wisconsin"Wyoming"

2.2.4 function access

> attach (state) The following objects are masked from package:datasets:

2.2.4 function access

> attach (state) The following objects are masked from package:datasets: state.abb, state.area State.name > state.name [1] "Alabama"Alaska" [3] "Arizona"Arkansas" [5] "California"Colorado" [7] "Connecticut"Delaware" [9] "Florida"Georgia" [11] "Hawaii"Idaho" [13] " Illinois "" Indiana "[15]" Iowa "Kansas" [17] "Kentucky"Louisiana" [19] "Maine"Maryland" [21], Massachusetts "Michigan" [23] "Minnesota"Mississippi" [25] "Missouri"Montana" [27] " Nebraska "" Nevada "[29]" New Hampshire "New Jersey" [31] "New Mexico"New York" [33] "North Carolina"North Dakota" [35], Ohio "" Oklahoma "[37]" Oregon "" Pennsylvania "[39]" Rhode Island "" South Carolina "[41]" South Dakota "" Tennessee "[43]" Texas "Utah" [45] "Vermont"Virginia" [47] "Washington"West Virginia" [49] "Wisconsin"Wyoming" I believe you have a better understanding of "R language lists and data boxes", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report