Loop through a .csv file in R, computing relative frequencies? -


I'm new to R and I'm trying to create one. Me and some frequencies are counted in this file and the values ​​associated with them are either 10, NA, or -4. What I want to do is known through each vertical line and then calculates their frequencies. I'm sure this is an easy script, but I'm not sure how R's syntax works so far. Can anyone get me started on this?

The exact script can vary depending on your input, what type of output do you want (just interactive Has been printed on the console? CCV? Written), but here's my attempt:

Read the data in CSV - it assumes that the heading & lt; - read.csv (file = "yourfile.csv") # For now, use this fake data & lt; Receive the frequency of values ​​for each column - data.frame (x = c (-4, 0, 1, 1, -4, n, suppose data is applied in each column (x = DAT, margin) , NA, 0), Y = C (1, 1, 1, 0, -4, NA, 0, NA)) = 2, Fun = function (x) {summary (factor (x)}}

The apply function applies to the function that you give it (fun) the margin of data given by you (1 = rows, 2 = column) You can give any function you want. Passing FUN = summary will give you the mean, minimum, maximum, etc. of each column (because they are numeric). But the default method for the summary () of factors is Frequency, which is what you want. Instead of going into, move the trick to see your number as a factor R: Define an anonymous function function (x) (applicable to know that by x you have taken columns one by one Are talking about this). Set the X to convert the X to a factor ( factor (x) ) and then summarize that factor it will return a matrix with frequencies for each column.

Never the best code, but I think it will get you what you need.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -