I'm sure this is pretty simple, but it's Friday afternoon, and I just don't see it... In a data frame with a categorical/character factor, I want to add another column giving, for each observation, the frequency of that factor level. An example, where the variable of interest is family: > data("Donner", package="vcdExtra") > str(Donner) 'data.frame': 90 obs. of 5 variables: $ family : Factor w/ 10 levels "Breen","Donner",..: 9 1 1 1 1 1 1 1 1 1 ... $ age : int 23 13 1 5 14 40 51 9 3 8 ... $ sex : Factor w/ 2 levels "Female","Male": 2 2 1 2 2 1 2 2 2 2 ... $ survived: int 0 1 1 1 1 1 1 1 1 1 ... $ death : POSIXct, format: "1846-12-29" NA ... > table(Donner$family) Breen Donner Eddy FosdWolf Graves Keseberg McCutchen MurFosPik 9 14 4 4 10 4 3 12 Other Reed 23 7 > Here, I want to create a new variable, family.size, where all the Breens have 9, the Donners, 14, and so on... -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. & Chair, Quantitative Methods York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
Hi. Here is one solution: table(Donner$family)[Donner$family] Andrija On Fri, Apr 11, 2014 at 10:40 PM, Michael Friendly <friendly@yorku.ca>wrote:> I'm sure this is pretty simple, but it's Friday afternoon, and I just > don't see it... > > In a data frame with a categorical/character factor, I want to add another > column giving, for each observation, the frequency of that factor level. > > An example, where the variable of interest is family: > > > data("Donner", package="vcdExtra") > > str(Donner) > 'data.frame': 90 obs. of 5 variables: > $ family : Factor w/ 10 levels "Breen","Donner",..: 9 1 1 1 1 1 1 1 1 1 > ... > $ age : int 23 13 1 5 14 40 51 9 3 8 ... > $ sex : Factor w/ 2 levels "Female","Male": 2 2 1 2 2 1 2 2 2 2 ... > $ survived: int 0 1 1 1 1 1 1 1 1 1 ... > $ death : POSIXct, format: "1846-12-29" NA ... > > table(Donner$family) > > Breen Donner Eddy FosdWolf Graves Keseberg McCutchen > MurFosPik > 9 14 4 4 10 4 3 12 > Other Reed > 23 7 > > > > Here, I want to create a new variable, family.size, where all the Breens > have 9, > the Donners, 14, and so on... > > -- > Michael Friendly Email: friendly AT yorku DOT ca > Professor, Psychology Dept. & Chair, Quantitative Methods > York University Voice: 416 736-2100 x66249 Fax: 416 736-5814 > 4700 Keele Street Web: http://www.datavis.ca > Toronto, ONT M3J 1P3 CANADA > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]
I bemoan the fact that I can not run R or Rstudio on my iPad. A possible work around would be to set up a server (probably under Linux), and get the server to present a web page that to would allow me to run R on the server. I have searched the web for a clear, simple answer on how to do this but can not find one. There are answers, but not for someone who has not built a Linux server. Can someone provide either a reference to, or a short explanation of how I can build the server, get R or RStudio to run on it, and get the server and its R or RStudio program available to me on my iPad? I can probably find guidance on how to build an Apache server under Linux. Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.