arrays - Function similar to head() in Matlab -


I'm just trying to figure out that head in Matlab < / Code> to r ? It should display / print the top 5 rows of an array. Therefore, given the following table

  var1 = transpose (1: 6); Var2 = Transges (2: 7); Aa = table (var1, var2);  

I'm searching for a funtion xx which generates as soon as:

  aa (1: 5) , :)  

ans =

  var1 var2 _________ 2 2 3 3 4 4 5 5 6  

Something like this: xx (aa)

I can definitely use the above indexed, but it would be more convenient with a function. I head () broadly R .

If you want all the top rows, then just mydata [ 1: 5,] .

I use the following toys from a certain person: -) cgwtools package, which allows you to specify how many items to display and if desired elements The option to leave is as soon as possible, I decided not to maintain the dimension to make it easy to check a list object feel free to take this code & amp; Modify your needs (for example, if you only want "head" of your data, then remove the last numel element returning part).

  short> -function (x = cec (1, 20), number = 4, skipel = 0, ynam = deparse (option (x)) {ynam & lt; - as.character (ynam) ynam & lt; - gsub ("", "", ynam) if (is.list (x)) x & lt; - unlist (t (x)) if (2 * numel & gt; = length (x)) {print (x)} else {frist = 1 + skipel last = Numel + skipel cat (paste (ynam, "[", Cat ("... ... \ n"), "fright", "[", "thru", ynam, "[", last, "] \ n", sep = "")) print (x [frist: last] (Paste (ynam, "[", length (x) - numel - skipel + 1, "] through", ynam, "[", length (x) - skipal,] () () () () () () ) () () () () () Div>  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -