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 in Others by Avinash
• 1,260 points
18 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 by Sohail
• 2,960 points

Related Questions In Others

0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
974 views
0 votes
1 answer
0 votes
0 answers

how to list the contents of a asset into an event

May 29, 2019 in Others by anonymous
195 views
0 votes
0 answers

How to open a new tab or a new window while writing an exam in AI - Onlime Remote Proctored

How to open a new tab or ...READ MORE

Jul 20, 2020 in Others by vimalkamal
• 120 points
2,324 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
435 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
478 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
4,345 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
502 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 in Others by Sohail
• 2,960 points
25 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 in Others by Sohail
• 2,960 points
26 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP