Hello, Thanks in advance for any help, I have read a CSV file in which there is a column for an IP addr as in: tmpInFile$V2 [1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" [5] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" [9] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" If I want to find the IP addr that has the highest occurrence (129.46.71.19, in this case), is there a simple way to do this? Thanks Shank [[alternative HTML version deleted]]
try this:> x[1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" [7] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19"> table(x)x 129.46.71.19 74.125.224.38 10 2> which.max(table(x))129.46.71.19 1 On Thu, Mar 17, 2011 at 6:06 PM, Khanvilkar, Shashank <skhanvil at qualcomm.com> wrote:> Hello, > Thanks in advance for any help, > > I have read a CSV file in which there is a column for an IP addr as in: > > tmpInFile$V2 > ?[1] "74.125.224.38" "74.125.224.38" "129.46.71.19" ?"129.46.71.19" > ?[5] "129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" > ?[9] "129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" > > If I want to find the IP addr that has the highest occurrence (129.46.71.19, in this case), is there a simple way to do this? > > Thanks > Shank > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
On Thu, Mar 17, 2011 at 10:06:21PM +0000, Khanvilkar, Shashank wrote:> Hello, > Thanks in advance for any help, > > I have read a CSV file in which there is a column for an IP addr as in: > > tmpInFile$V2 > [1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" > [5] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > [9] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > > If I want to find the IP addr that has the highest occurrence (129.46.71.19, in this case), is there a simple way to do this? > ...Does this come close?> tmpInFile <- read.csv("X") > tmpInFileNr V2 1 1 74.125.224.38 2 2 74.125.224.38 3 3 129.46.71.19 4 4 129.46.71.19 5 5 129.46.71.19 6 6 129.46.71.19 7 7 129.46.71.19 8 8 129.46.71.19 9 9 129.46.71.19 10 10 129.46.71.19 11 11 129.46.71.19 12 12 129.46.71.19> table(tmpInFile$V2)129.46.71.19 74.125.224.38 10 2>Peace, david -- David H. Wolfskill r at catwhisker.org Depriving a girl or boy of an opportunity for education is evil. See http://www.catwhisker.org/~david/publickey.gpg for my public key. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 196 bytes Desc: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110317/bdf24fe5/attachment.bin>
Thanks> which.max(table(x))129.46.71.19 10 How do I get only "129.46.71.19" back as a str... -----Original Message----- From: jim holtman [mailto:jholtman at gmail.com] Sent: Thursday, March 17, 2011 4:39 PM To: Khanvilkar, Shashank Cc: r-help Subject: Re: [R] Histograms with strings, try this:> x[1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" [7] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19"> table(x)x 129.46.71.19 74.125.224.38 10 2> which.max(table(x))129.46.71.19 1 On Thu, Mar 17, 2011 at 6:06 PM, Khanvilkar, Shashank <skhanvil at qualcomm.com> wrote:> Hello, > Thanks in advance for any help, > > I have read a CSV file in which there is a column for an IP addr as in: > > tmpInFile$V2 > ?[1] "74.125.224.38" "74.125.224.38" "129.46.71.19" ?"129.46.71.19" > ?[5] "129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" > ?[9] "129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" ?"129.46.71.19" > > If I want to find the IP addr that has the highest occurrence (129.46.71.19, in this case), is there a simple way to do this? > > Thanks > Shank > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
On Mar 17, 2011, at 6:06 PM, Khanvilkar, Shashank wrote:> Hello, > Thanks in advance for any help, > > I have read a CSV file in which there is a column for an IP addr as > in: > > tmpInFile$V2 > [1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" > [5] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > [9] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > > If I want to find the IP addr that has the highest occurrence > (129.46.71.19, in this case), is there a simple way to do this?Try: > vec <- c( + "74.125.224.38", "74.125.224.38", "129.46.71.19", "129.46.71.19", + "129.46.71.19", "129.46.71.19", "129.46.71.19", "129.46.71.19", + "129.46.71.19", "129.46.71.19", "129.46.71.19", "129.46.71.19") > table(vec) vec 129.46.71.19 74.125.224.38 10 2 > which.max(table(vec)) 129.46.71.19 1 > table(vec)[which.max(table(vec))] 129.46.71.19 10> > Thanks > Shank > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.David Winsemius, MD West Hartford, CT
On 03/18/2011 09:06 AM, Khanvilkar, Shashank wrote:> Hello, > Thanks in advance for any help, > > I have read a CSV file in which there is a column for an IP addr as in: > > tmpInFile$V2 > [1] "74.125.224.38" "74.125.224.38" "129.46.71.19" "129.46.71.19" > [5] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > [9] "129.46.71.19" "129.46.71.19" "129.46.71.19" "129.46.71.19" > > If I want to find the IP addr that has the highest occurrence (129.46.71.19, in this case), is there a simple way to do this? >Hi Shank, Although there have been a couple of answers involving "table": library(prettyR) Mode(tmpInFile$V2) [1] "129.46.71.19" Jim