2021年3月20日星期六

How to iterate over list of tables and find proportions in R

I have a list of tables in R in which each table is a column from a larger dataset. These are tables instead of dataframes as I want to use prop.table to find the percentage of occurance for the data.

I'm new to R so I have been manually finding the percentage one-by-one for each table. I am trying to make this a for loop instead but it doesn't seem to work. The loop is looping the correct number of times but it is giving me the results for the last table "Actually_Malicious" each time it opens a new View() table.

categorical_variables_list = list(Download_Source,                                     TLD,                                     Download_Speed,                                     Executable_Code_Maybe_Present_in_Headers,                                    No_Executable_Code_Found_In_Headers,                                    Evidence_of_Code_Obfuscation,                                    Actually_Malicious)      for(col in 1:length(categorical_variables_list)){        tab <- table(categorical_variables_list[[col]]);     View(tab);    prop <- prop.table(tab);     View(prop);  }  
https://stackoverflow.com/questions/66729037/how-to-iterate-over-list-of-tables-and-find-proportions-in-r March 21, 2021 at 01:06PM

没有评论:

发表评论