I have a dataset that looks like this:
Column 1 Column 2 Column 3 Column 4
Male 35 USA DC
Female 10 USA NYC
I've agregated this dataframe to calculate the number of unique values in each column and the respective percentage of the total number of rows.
So my new dataframe looks like this:
I've got a data frame that looks like this (this is just examplary):
Column Name Nominal Percent
1 Col1 3 1.00
2 Col2 69333 99.51
3 Col3 65766 94.40
4 Col4 60727 87.16
What I want for the second dataframe is to create a third column - sample modality. The new column should be a sample of each column. Like this:
Column Name Nominal Percent Sample_1
1 Col1 3 1.00 Male
2 Col2 69333 99.51 25
I can't recall how to pull this off automatically for each column. I don't want to manually type each column-name. Any hints?
newdat$Sample_1 <- sapply(origdat, sample, size=1)? Note that they will likely be upconverted tocharacter(since at least one of your columns ischaracter, none of them will retain theirnumericorintegerclass.data.frame(ColumnName=names(origdat), Sample_1=sapply(origdat, sample, size=1), stringsAsFactors=FALSE), then usemergeor any of the joins withindplyr.