You are on page 1of 13
1) with suitable ceamele, crplain the date Structures available in 2 programming? Pate Structures in & Programming: Pate structures ore very imeortant to understand. Pata structure are the objcets whieh we will manipulate in our drvg-—to-devy basis in 2. Deming with rbcet conversions is the most common Sourecs of dusonirs for beginners. We enn Stuy that everigthing in © is on object. LE has many data structures, whieh inelude: f-tomie veetor Z-List S-Xer ay H-Matrie es s-patn Frame b-Fretors t-vVeetors A veetor is the vasie data structure in 2, wr we en Shy veetors mre the most basic & data rhjcets. There are sip tees oF atomic veetors such as logical, integer, charneter, dowble, and raw. "x veetor is m crllcetion vf elements whieh is most ermmonlyy vf mode character, integer, logiem or numeric” 4 veetor ean be one of the following two tings: + Atomie veetor + Lists Eramele: # & progcnm to illustrate Vcetor € Veetorsrdercd calleetion vf same date tigee) ~Y = Ul, 3, 5) 7, 9) #€ Printing those elements in console print(e) 8 we ut: io 6 ah A-list In L, the list is the container. Unlike an atomic vector, the list is not restricted tr be a single mode. > list contains a miPture of data types. The list is msn Known as generic veetors beemuse the coment of the list can be of aug Inge of B rbcet. " list is w special tigee of veetor in whieh crch clement ean be a different type." we ean ercate aw list with the hele of listO or as.listO. we ean use veetorO to ercate a requ od length ometug list. Eramele: # © program to illustrate a List # the first attributes is & numeric veetor # containing the empluger LPS whieh is # erented using the 'e' command here umpLa = of, 4, 3, 4) € The scernd attribute is the emelogee name € whieh is ereated using this line vf erde here € whieh is the charneter veetor umeName = eC"Pevi", "Sandeep", "Subham", "Shibe") # the third attribute is the number of emplogees € which is m single numeric varinvle. number Oteme = 4 # wel oan combine Ml these three different € date types intr ow list # containing the details of employees # which edn be dane using & list command emgList = listtempLd, emgname, numberoteme) printCempList) 9 ute ut: CLI Ciiz34 CLA+TI Ct "evi" "Sandece" "Subham" "Shin" leo eg, S-Aer mgs There is another tigpe of date motets whieh ean store data in more than two dimensions Known as archys. "An orcdag is a collection of a similar data Age with contiguons memory Mlrention." Suppose, if we ereate an army rf dimension (4, 3, 4) then it erentes four rcetangular matriees of tw rows and three erlumns. En 2, an array is ercated with the help of array function. This funetion takes a veetor as an ingut and uses the valuc in the dim gacameter to erento in Array. Eramele: € © program to illustrate an acrhig A = arrhugl € Taking Scqucnee of clements od, 4) 3, 4) 5) by 1) P)) € cremting two reetangular matrices € cneh with two rows and two columns dim = elt, 2, 2) ) pcintOD outputs oak Sie ez ei [2,124 ie ial Chis 7 C4,1 oF A-Matriees A matriP is an & ojcet in whieh the cloements are arranged in m two-dimensional reetangular Lagout. Cn the matrie, cloments of the same atomic types are contained. For mathemationl emleulation, this ean use ao matrip containing the numeric cloment. > matrip is ereated with the help of the matriPO function in tL. Syntee The basic signtaP rf ercoting a matriv is as follows: metriPldate, no—rw, no—erl, by—row, dim_—namc) Eramele: # © program to illustrate a matriv 4 = matried € Taking scqucnee of elements edt) 2) 3) Hy 5) by 1) %) VD, # Nov of rows and edlumns new = 3, nevl = 3, € By dctonult matriees are # in column-wise order € Sv this parameter decides # Wow to arrange the matrie byw = TRUE ) gcint) Output: il G2, Gad lel CA14 56 C3177 spate Frames: 4 date frame is m two-dimensional accoy-like Structure, or Wo ean Shug it is mW table in whieh Caeh erlumn contains the value of one varinele, and cow erntnins the set of value from caeh column. there ace the Following eharneteristies of a data frame: fthe erlumn name will be non-emety. Z.The cow names will be wnlqne. 3. data frame stored numeric, faetor or charactor tinge date. AH.Eoen erlumn will eontain same number of data items. Eramele: € © program to illustrate datatrame # A veetor whieh is m charneter veetor Name = e("Aminga', "Lai", "rAsish") # A veetor whieh is m charneter veetor Language = eC"e", "Python", "“Favn") # A vector whieh is m numeric veetor Age = e44, 25, 45) € Tr erente datnframe use datatrame command # ond then pass cneh of the veetors # we have ereated as mrguments # tr the function datetrameO df = dateframe(Name, Language, gc) grintCat) 9 ute ut: Name Language ge [ Aminn B22 + th, Python 25 3 Asish Fava 45 b-Fretors Foators are oso date vbicets that are used +o emtegorice the data and store it as levels. Faetors ean store both strings and integers. Columns Weve limited number oF unique vilues $0 Anat fretors ace viryy useful in _erlumns. Lt is vervy useful in date analysis for statistical modeling. 4netors ore erented with the hele of fretrO function by taking © vector as an ingut parameter. Eramele: € © program ty illustrate fretors # crenting fretor using fretocO fre = fretor(ec’Male", "Female", "Malo", "Male", "Female", "Male", "“Fomale")) grintctre) Sutgut: ClT Male Female Male Male Female Male Female Luvas: Fomee Male ) a. write & erde to generate first nm terms of 0 Fivondeel Series? torms=as.integer(rendine(aromet="how many turmsé")) numl=0 num =! num= ifCtermsc=O$ gcintC'enter a grsitive integer") 5 use z ifCterms==1) printC'fibonaeei Sequenec:") printed 3 use § printC'Fivonneei Sequences") gcintCruml) printGnume) whileCeount < torms) i nthanumf + [ pcint(nth) num{=nume numt=nth eruntaeunt + 1 g vo @ how many torms?

You might also like