Re: [R] Problem with comparing multiple data sets
Hi everyone. I tried the (modeest) package on my initial test data and it worked. However, it doesn't work on the entire data set. I saved one of the protions that gives error. (Not for all of the values but for some of them). For example: lines 36 and 37 and 39 correctly show the mode value but 38 and 40 are not correct. Such error is repeated for many of the values. [36,] 2 [37,] 2 [38,] Numeric,3 [39,] 1 [40,] Numeric,3 #This is what I did: df- read.csv(file=Part1-modif.csv, head=TRUE, sep=,) Out- apply(df[,2:length(df)],1, mfv) t(t(Out)) #This is the data set structure(list(terms = structure(c(2L, 4L, 4L, 4L, 3L, 1L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L), .Label = c(#authentication,access control, #privacy,personal data, #security,malicious,security, data controller, id management,security, password,recovery), class = factor), class.1 = c(2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 2L), class.2 = c(2L, 2L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 2L), class.3 = c(2L, 0L, 2L, 2L, 1L, 1L, 0L, 0L, 0L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c(terms, class.1, class.2, class.3), class = data.frame, row.names = c(NA, -50L)) also when I try to include the terms to the result it gives me an error: mode.names- data.frame (df[,1],Out) Error in data.frame(df[, 1], Out) : arguments imply differing number of rows: 50, 3 On Thu, May 28, 2015 at 9:24 AM, Mohammad Alimohammadi mxalimoha...@ualr.edu wrote: Thank you David for your help ! On Wed, May 27, 2015 at 7:31 PM, David L Carlson dcarl...@tamu.edu wrote: cat(paste0([, 1:length(Out), ] #dac , Out), sep=\n) David *From:* Mohammad Alimohammadi [mailto:mxalimoha...@ualr.edu] *Sent:* Wednesday, May 27, 2015 2:29 PM *To:* David L Carlson; r-help@r-project.org *Subject:* Re: [R] Problem with comparing multiple data sets Thanks David it worked ! One more thing. I hope it's not complicated. Is it also possible to display the terms for each row next to it? for example: [1] #dac2 [2] #dac0 [3] #dac1 ... On Wed, May 27, 2015 at 2:18 PM, David L Carlson dcarl...@tamu.edu wrote: Save the result of the apply() function: Out - apply(df[ ,2:length(df)], 1, mfv) Then there are several options: Approximately what you asked for data.frame(Out) t(t(Out)) More typing but exactly what you asked for cat(paste0([, 1:length(Out), ] , Out), sep=\n) David L. Carlson Department of Anthropology Texas AM University -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mohammad Alimohammadi Sent: Wednesday, May 27, 2015 1:47 PM To: John Kane; r-help@r-project.org Subject: Re: [R] Problem with comparing multiple data sets Ok. so I read about the (modeest) package that gives the results that I am looking for (most repeated value). I modified the data frame a little and moved the text to the first column. This is the data frame with all 3 possible classes for each term. = structure(list(terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor), class.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L), class.2 = c(2L, 2L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), class.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 1L, 2L)), .Names = c(terms, class.1, class.2, class.3), class = data.frame, row.names = c(NA, -49L)) = #Then I applied the function below: == library(modeest) df- read.csv(file=short.csv
Re: [R] Problem with comparing multiple data sets
https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help] [ https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help]] [ https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help] [ https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help]]] PLEASE do read the posting guide http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html] [ http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html]] [ http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html] [ http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html]]] and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth [ http://www.inbox.com/earth] [http://www.inbox.com/earth [http://www.inbox.com/earth]] [http://www.inbox.com/earth [http://www.inbox.com/earth] [ http://www.inbox.com/earth [http://www.inbox.com/earth]]] -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu] [ http://ualr.edu [http://ualr.edu]] [ http://ualr.edu/ [http://ualr.edu/] [http://ualr.edu/ [ http://ualr.edu/]]] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J]] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J]]] FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing [ http://www.inbox.com/photosharing] [ http://www.inbox.com/photosharing [http://www.inbox.com/photosharing]] to find out more! -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu] [ http://ualr.edu/ [http://ualr.edu/]] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J]] FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth [http://www.inbox.com/earth ] -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help] PLEASE do read the posting guide http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html] and provide commented, minimal, self-contained, reproducible code. Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords protects your account. Check it out at http://mysecurelogon.com/password-manager [ http://mysecurelogon.com/password-manager] -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu/] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks orcas on your desktop! Check it out at http://www.inbox.com/marineaquarium -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics
Re: [R] Problem with comparing multiple data sets
just started using R. I don't know where I am going with this. I appreciate any help. On Sat, May 23, 2015 at 8:23 AM, John Kane jrkrid...@inbox.com wrote: Hi Mohammad Welcome to the R-help list. There probably is a fairly easy way to what you want but I think we probably need a bit more background information on what you are trying to achieve. I know I'm not exactly clear on your decision rule(s). It would also be very useful to see some actual sample data in useable R format.Have a look at these links http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example ] [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example ]] and http://adv-r.had.co.nz/Reproducibility.html [ http://adv-r.had.co.nz/Reproducibility.html] [ http://adv-r.had.co.nz/Reproducibility.html [ http://adv-r.had.co.nz/Reproducibility.html]] for some hints on what you might want to include in your question. In particular, read up about dput() in those links and/or see ?dput. This is the generally preferred way to supply sample or illustrative data to the R-help list. It basically creates a perfect copy of the data as it exists on 'your' machine so that R-help readers see exactly what you do. John Kane Kingston ON Canada -Original Message- From: mxalimoha...@ualr.edu Sent: Fri, 22 May 2015 12:37:50 -0500 To: r-help@r-project.org Subject: [R] Problem with comparing multiple data sets Hi everyone, I am very new to R and I have a task to do. I appreciate any help. I have 3 data sets. Each data set has 4 columns. For example: Class Comment Term Text 0 com1aactext1 2 com2aaxtext2 1 com3vvxtext3 Now I need t compare the class section between 3 data sets and assign the most available class to that text. For example if text1 is assigned to class 0 in data set 12 but assigned as 2 in data set 3 then it should be assigned to class 0. If they are all the same so the class will be the same. The ideal thing would be to keep the same format and just update the class. Is there any easy way to do this? Thanks a lot. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help] [ https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help]] PLEASE do read the posting guide http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html] [ http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html]] and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth [http://www.inbox.com/earth] [http://www.inbox.com/earth [http://www.inbox.com/earth]] -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu] [ http://ualr.edu/ [http://ualr.edu/]] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J]] FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing [ http://www.inbox.com/photosharing] to find out more! -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu/] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu
Re: [R] Problem with comparing multiple data sets
Ok. so I read about the (modeest) package that gives the results that I am looking for (most repeated value). I modified the data frame a little and moved the text to the first column. This is the data frame with all 3 possible classes for each term. = structure(list(terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor), class.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L), class.2 = c(2L, 2L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), class.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 1L, 2L)), .Names = c(terms, class.1, class.2, class.3), class = data.frame, row.names = c(NA, -49L)) = #Then I applied the function below: == library(modeest) df- read.csv(file=short.csv, head= TRUE, sep=,) apply(df[ ,2:length(df)], 1, mfv) # It gives the most frequent value for each row which is what I need. The only problem is that all the values are displayed in one single row. [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 0 0 0 0 2 1 2 It would be much better to show them in separate rows. For example: [1] 0 [2] 0 [3] 1 Any idea how to do this? On Wed, May 27, 2015 at 10:11 AM, Mohammad Alimohammadi mxalimoha...@ualr.edu wrote: Hi Jim, Thank you for your advice. I'm not sure how to exactly incorporate this function though. I added a portion of the actual data sets. all 3 data sets have the same items (text) with different class values. So I need to assign the most repeated class (0,1,2) for each text. For example: if line1 has text aaa. It may be assigned to class 0 in dat1, 2 in dat 2 and 0 in dat3. in this case the aaa will be assigned to 0 (most repeated value). So it goes for each text. I really appreciate your help. = *dat1* structure(list(class.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L), terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor)), .Names = c(class.1, terms), class = data.frame, row.names = c(NA, -49L)) *dat2* structure(list(class.2 = c(2L, 2L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor)), .Names = c(class.2, terms), class = data.frame, row.names = c(NA, -49L)) *dat3* structure(list(class.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 1L, 2L), terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor)), .Names = c(class.3, terms), class = data.frame, row.names = c(NA, -49L)) === On Sun, May 24, 2015 at 1:15 AM, Jim Lemon drjimle...@gmail.com wrote: Hi Mohammad, You know, I thought this would be fairly easy, but it wasn't really. df1-data.frame(Class=c(0,2,1),Comment=c(com1,com2,com3), Term=c(aac,aax,vvx),Text=c(text1,text2,text3)) df2-data.frame(Class=c(0,2,1),Comment=c(com1,com2,com3), Term=c(aac,aax,vvx),Text=c
Re: [R] Problem with comparing multiple data sets
Thanks David it worked ! One more thing. I hope it's not complicated. Is it also possible to display the terms for each row next to it? for example: [1] #dac2 [2] #dac0 [3] #dac1 ... On Wed, May 27, 2015 at 2:18 PM, David L Carlson dcarl...@tamu.edu wrote: Save the result of the apply() function: Out - apply(df[ ,2:length(df)], 1, mfv) Then there are several options: Approximately what you asked for data.frame(Out) t(t(Out)) More typing but exactly what you asked for cat(paste0([, 1:length(Out), ] , Out), sep=\n) David L. Carlson Department of Anthropology Texas AM University -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mohammad Alimohammadi Sent: Wednesday, May 27, 2015 1:47 PM To: John Kane; r-help@r-project.org Subject: Re: [R] Problem with comparing multiple data sets Ok. so I read about the (modeest) package that gives the results that I am looking for (most repeated value). I modified the data frame a little and moved the text to the first column. This is the data frame with all 3 possible classes for each term. = structure(list(terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor), class.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L), class.2 = c(2L, 2L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), class.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 2L, 1L, 2L)), .Names = c(terms, class.1, class.2, class.3), class = data.frame, row.names = c(NA, -49L)) = #Then I applied the function below: == library(modeest) df- read.csv(file=short.csv, head= TRUE, sep=,) apply(df[ ,2:length(df)], 1, mfv) # It gives the most frequent value for each row which is what I need. The only problem is that all the values are displayed in one single row. [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 1 1 1 0 0 0 0 2 1 2 It would be much better to show them in separate rows. For example: [1] 0 [2] 0 [3] 1 Any idea how to do this? On Wed, May 27, 2015 at 10:11 AM, Mohammad Alimohammadi mxalimoha...@ualr.edu wrote: Hi Jim, Thank you for your advice. I'm not sure how to exactly incorporate this function though. I added a portion of the actual data sets. all 3 data sets have the same items (text) with different class values. So I need to assign the most repeated class (0,1,2) for each text. For example: if line1 has text aaa. It may be assigned to class 0 in dat1, 2 in dat 2 and 0 in dat3. in this case the aaa will be assigned to 0 (most repeated value). So it goes for each text. I really appreciate your help. = *dat1* structure(list(class.1 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L), terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor)), .Names = c(class.1, terms), class = data.frame, row.names = c(NA, -49L)) *dat2* structure(list(class.2 = c(2L, 2L, 2L, 2L, 0L, 0L, 2L, 0L, 0L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 0L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 0L, 0L, 0L, 0L, 1L, 1L, 1L), terms = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 2L), .Label = c(#dac, #mac,#security, accountability,anonymous, data security,encryption,security ), class = factor)), .Names = c(class.2, terms), class = data.frame, row.names = c(NA, -49L)) *dat3* structure(list(class.3 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L
Re: [R] Problem with comparing multiple data sets
, 7, 8, 9, 10), class = factor), bb = c(10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L)), .Names = c(aa, bb), row.names = c(NA, -10L), class = data.frame) dat2 - structure(list(aa = 1:10, bb = c(10L, 9L, 8L, 7L, 6L, 5L, 4L, 3L, 2L, 1L)), .Names = c(aa, bb), row.names = c(NA, -10L), class = data.frame) dat1 dat2 # looks a lot like dat1 with(dat1, aa*bb) with(dat2 , aa*bb) str(dat1) str(dat2) === John Kane Kingston ON Canada -Original Message- From: mxalimoha...@ualr.edu Sent: Mon, 25 May 2015 12:14:46 -0500 To: jrkrid...@inbox.com Subject: Re: [R] Problem with comparing multiple data sets Hi John. Thank you for your response. Here is a small portion of my actual data set. What I am supposed to do is to use a function similar to mode function in excel to find the most frequent value (class) for each term. V1 V2 V3 V4 1 class 1 class 2 class 3 terms 2 0 2 0 #dac 3 0 2 0 #dac 4 0 2 0 #dac 5 0 2 0 #dac 6 1 0 1 #dac 7 0 0 0 #dac Since I just started using R. I don't know where I am going with this. I appreciate any help. On Sat, May 23, 2015 at 8:23 AM, John Kane jrkrid...@inbox.com wrote: Hi Mohammad Welcome to the R-help list. There probably is a fairly easy way to what you want but I think we probably need a bit more background information on what you are trying to achieve. I know I'm not exactly clear on your decision rule(s). It would also be very useful to see some actual sample data in useable R format.Have a look at these links http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example] [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example [ http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example]] and http://adv-r.had.co.nz/Reproducibility.html [ http://adv-r.had.co.nz/Reproducibility.html] [ http://adv-r.had.co.nz/Reproducibility.html [ http://adv-r.had.co.nz/Reproducibility.html]] for some hints on what you might want to include in your question. In particular, read up about dput() in those links and/or see ?dput. This is the generally preferred way to supply sample or illustrative data to the R-help list. It basically creates a perfect copy of the data as it exists on 'your' machine so that R-help readers see exactly what you do. John Kane Kingston ON Canada -Original Message- From: mxalimoha...@ualr.edu Sent: Fri, 22 May 2015 12:37:50 -0500 To: r-help@r-project.org Subject: [R] Problem with comparing multiple data sets Hi everyone, I am very new to R and I have a task to do. I appreciate any help. I have 3 data sets. Each data set has 4 columns. For example: Class Comment Term Text 0 com1aactext1 2 com2aaxtext2 1 com3vvxtext3 Now I need t compare the class section between 3 data sets and assign the most available class to that text. For example if text1 is assigned to class 0 in data set 12 but assigned as 2 in data set 3 then it should be assigned to class 0. If they are all the same so the class will be the same. The ideal thing would be to keep the same format and just update the class. Is there any easy way to do this? Thanks a lot. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help] [ https://stat.ethz.ch/mailman/listinfo/r-help [ https://stat.ethz.ch/mailman/listinfo/r-help]] PLEASE do read the posting guide http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html] [ http://www.R-project.org/posting-guide.html [ http://www.R-project.org/posting-guide.html]] and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! Check it out at http://www.inbox.com/earth [http://www.inbox.com/earth] [http://www.inbox.com/earth [http://www.inbox.com/earth]] -- Mohammad Alimohammadi | Graduate Assistant University of Arkansas at Little Rock | College of Science and Mathematics (CSAM) 501.346.8007 | mxalimoha...@ualr.edu | ualr.edu [http://ualr.edu] [ http://ualr.edu/ [http://ualr.edu/]] Public URL: http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J] [ http://scholar.google.com/citations?user=MsfN_i8J [ http://scholar.google.com/citations?user=MsfN_i8J
[R] Problem with comparing multiple data sets
Hi everyone, I am very new to R and I have a task to do. I appreciate any help. I have 3 data sets. Each data set has 4 columns. For example: Class Comment Term Text 0 com1aactext1 2 com2aaxtext2 1 com3vvxtext3 Now I need t compare the class section between 3 data sets and assign the most available class to that text. For example if text1 is assigned to class 0 in data set 12 but assigned as 2 in data set 3 then it should be assigned to class 0. If they are all the same so the class will be the same. The ideal thing would be to keep the same format and just update the class. Is there any easy way to do this? Thanks a lot. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.