How to run the table function in R across multiple variables and compile the results into a new dataset using a function

0 votes
Any suggestions as to how I can automate this process for several more variables?
Jun 13, 2022 in Others by Avinash
• 1,260 points
700 views

1 answer to this question.

0 votes
0
Your b effort would be a good place to start because it was so near. If you remove the class "table" from tables, I believe the only reason you are reshaping is because of data.frame(table(), which you don't need to do.

Additionally, I would attempt to finish all of the function's processing for a single variable, such as adding headers, labels, etc. In this manner, you may verify that your function does what you want it to do on a single variable before beginning the loop over all variables.

# (b) myfxn — function (x, header = "variable" y = vcat = rownames(y), y, stringsAsFactors = FALSE; y = unclass(table(x, df$cat)) colnames(y) = gsub('d', ", colnames(y));
y) = rbind(c(header, rep(", ncol(y) - 1)), y)

myfxn(df$v1) # vcat low med high # 1 variable # an a 1 0 0 # b b 1 1
answered Jun 24, 2022 by Sohail
• 3,040 points

Related Questions In Others

0 votes
1 answer

How to unmerge multiple cells and transpose each value into a new column in Pandas dataframe from excel file

Try this: df = pd.read_excel("Sample_File.xlsx", header=[0,1,2,3,4,5], index_col = ...READ MORE

answered Jan 8, 2023 in Others by narikkadan
• 63,420 points
1,851 views
0 votes
1 answer

How to insert a new row in the specified cell only, of Excel sheet using c#?

I have this worksheet with a matrix ...READ MORE

answered Nov 24, 2022 in Others by narikkadan
• 63,420 points
1,864 views
0 votes
1 answer
0 votes
1 answer

How can I use a command button in excel to set the value of multiple cells in one click?

Try this: Private Scan As Integer Private Sub CommandButton1_Click() ...READ MORE

answered Oct 24, 2022 in Others by narikkadan
• 63,420 points
528 views
0 votes
1 answer

Big Data transformations with R

Dear Koushik, Hope you are doing great. You can ...READ MORE

answered Dec 18, 2017 in Data Analytics by Sudhir
• 1,610 points
761 views
0 votes
2 answers

Transforming a key/value string into distinct rows in R

We would start off by loading the ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
834 views
0 votes
1 answer

Finding frequency of observations in R

You can use the "dplyr" package to ...READ MORE

answered Mar 26, 2018 in Data Analytics by Bharani
• 4,660 points
5,542 views
0 votes
1 answer

Left Join and Right Join using "dplyr"

The below is the code to perform ...READ MORE

answered Mar 27, 2018 in Data Analytics by Bharani
• 4,660 points
854 views
0 votes
1 answer

Does Java have a IN operator or function like SQL

A Java-language was designed to be powerful ...READ MORE

answered May 30, 2022 in Others by Sohail
• 3,040 points

edited Jun 22, 2023 by Khan Sarfaraz 262 views
0 votes
1 answer

Ordering by the order of values in a SQL IN() clause

We can use expressions as well in ...READ MORE

answered May 31, 2022 in Others by Sohail
• 3,040 points
270 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP