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
138 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
• 2,960 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 in Others by narikkadan
• 52,400 points
101 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
• 52,400 points
256 views
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
• 52,400 points
145 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
511 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
576 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,731 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
582 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
• 2,960 points
67 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
• 2,960 points
97 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