I have summarized a column of a data frame (Call ID) which has an ID, so I The number is obtained In the given column, I want to convert it to another data frame (call this TOTALNUM), so I have two columns, the first column is the ID and the second column is the total number of each ID. Is this possible?
Sample data:
id < - c (1,2,3,4,5,1,2,3,1,5, 1,4,2,2,2) Notice & lt; - c ("A", "B", "C", "A", "B", "C", "A", "B", "C" A "," B "," C "," Data "id = info $ id & lt; - as.factor (data $ id) What I would like to do in a data frame: The top row will be the first column in a new data frame, the second row will be the second column in a new data frame.
summary (Figures $ Id) This is what I like to like the data frame:
ID number 1 4 2 5 3 2 4 2 5 2
Can take advantage of summary returns a vector of numbers with names for each value ID : & gt; Lies & lt; - Summary (Data $ id)> Data.frame (id = name (my album), nums = my.summary) ID number 1 1 4 2 2 5 3 2 4 4 2 5 5 2 < / Code> Or - and this approach is simpler - you can create a frequency table based on id And then convert it into a data frame: & gt; As.data.frame (table (id), responseName = "nums") ID number 1 1 4 2 2 3 3 2 4 4 2 5 5 2
No comments:
Post a Comment