r - Is a While Loop actually appropriate here or have I (once again) misunderstood the apply family of functions? -


I am a new user of R and more programs are used for loops functions with programs like Matab, but RK I am trying to shy away from the extremities in the strength and weaknesses of implementing the tasks. The only problem is that I am not 100% sure when one should go in favor of another, for example:

I have a series in which I want to convert to individual plots. I want to locate these plots at a particular point and then zoom into the area of ​​plot by determining the plot of Xml and Yelim so that the graph will contain only 80 or fewer digits

and now the code For (In German) = Weg = Kraft = Strain, Zeit = Time):

  Data MyData & lt #reads; - read.table (file, header = true, leave = 52, dec = ",") #establishes Are the fields of MyData what are the craft's & lt; - MyData [, 2] weg & lt; - MyData [3] Zeit & lt; - MyData [, 1] #Finds is the distance plot, the area in which I am interested in Weg_Values_at_Fmax & lt am the values ​​associated with maximum force; - weg [Joe (craft == max (craft))] initiates the next set values ​​of # rows, which in that time the loop will change from # to zero, second distance # distance on both sides of the value maximum force Linked with N & lt; - 0 Weg.index & lt; - Joe (weg> = Weg_Values_at_Fmax) - Weg_Values_at_Fmax [Length (Weg_Values_at_Fmax)] * (1/7) + n) & amp; weg & lt; = (Weg_Values_at_Fmax [lengt hour (Weg_Values_at_Fmax)] Weg_Values_at_Fmax [length (Weg_Values_at_Fmax)] * (1/7) - n)) #finally while loop which n until # Weg.index increase falls below a certain value (which Weg.index decreasing), 80 points in the case # While (length (Weg.index)> 80) {n & lt; - n + 0.0005 Weg.index & lt; - (Weg> = Weg_Values_at_Fmax] - Weg_Values_at_Fmax [Length (Weg_Values_at_Fmax)] * (1/6) + n) & amp; weg & lt; = (Weg_Values_at_Fmax [Length (Weg_Values_at_Fmax)] Weg_Values_at_Fmax [length (Weg_Values_at_Fmax)] * (1/6) - N))}  

then comes the notation:

  Plot (VG, Craft, Aksli = C (VG [Vegkindaks [1]], VG [VG. IndiX [length (VG. Indak)]), Yil = C (min (Craft) [Wegkindex [1: length (Wegkindex)] ], This code works fine because there is not too much data (craft [Weg.index [1: length (Weg.index)]])), main = file  

But I am hoping that this kind of data is a better way of handling the request for a while when I need to reduce the large data. I hope this question was quite specific and it is not a subject or anything like that. Thank you for your time and assistance.

I took the approach to keep data together in a data frame, and to find the desired range of values Using the percentile () function and its reverse ecdf () . The code below should not depend on any order of data. There should be a lot of records with the same "spotlight" craft value, but it should be corrected. Note that light is the first of matching values.

  plot.points = 80 #call Indicator of the line to highlight spotlight spotlight. Kraft & lt; - max (mydata $ Kraft_N) Spotlight & lt; - which (MyData $ Kraft_N == spotlight.kraft) [1] #get values ​​of quantiles up / down spotlight.kraft XP = c (ecdf (MyData $ Weg_mm) (MyData $ Weg_mm [headlines]) - 0.5 * plot .points / Nrow (MyData), ecdf (MyData $ Weg_mm) (MyData $ Weg_mm [headlines]) + 0.5 * plot.points / Nrow (MyData)) [0,1] out #adjust for quantiles if (XP [1] & LT; 0) XP & lt; - XP-XP [1] if (XP [2]> 1) XP & lt; - XP - XP [2] + 1xlims & lt; - quantile (MyData $ Weg_mm, XP) #possibly 80 actually showed no marks Nrow (subset (MyData, Weg_mm & gt; xlims [1] In & amp; Weg_mm & LT; xlims [2])) #get same Craft gives importance to ylims & lt; - Range (subset (MyData, Weg_mm & gt; xlims [1] & amp; Weg_mm & LT; xlims [2]) $ Kraft_N) plot (Weg, Craft, xlim = xlims, ylim = ylims)  

No need to use loops to do this.

As a side, your original code used this construct in small amounts.

  Weg_Values_at_Fmax [length (Weg_Values_at_Fmax)]  

event R as defined by the maximum (), it is always a This expression will always return the scaler value of Weg_Values_at_Fmax so the vector of length one.


Comments

Popular posts from this blog

winforms - C# Form - Property Change -

java - Algorithm negotiation fail SSH in Jenkins -

java - Messages from .properties file do not display UTF-8 characters -