From nfields at gmail.com Sun Jul 3 21:57:49 2016 From: nfields at gmail.com (affableambler) Date: Sun, 3 Jul 2016 12:57:49 -0700 (PDT) Subject: [datatable-help] Classify User Input with Unique Identification Numbers Message-ID: <1467575869840-4722458.post@n4.nabble.com> I'm somewhat new to R and am trying to create a function that will take user Input into a data frame, assign a new ID number to entries with new names, and give the same ID number to inputs with the same name. I wrote the following code: options(stringsAsFactors = FALSE) DbUpdate <- function(dataframe){ newline=c() newline$Machine_Name=readline("Machine Name: ") newline$Bet=as.double(readline("Bet: ")) newline$Return=as.double(readline("Return: ")) if(newline$Machine_Name %in% dataframe$Machine_Name) {newline$MachineID=dataframe$MachineID[which(dataframe$Machine_Name %in% newline$Machine_Name)]} else(newline$MachineID=sample(100:999,1,replace=T)) dataframe=rbind(dataframe,newline,make.row.names=F) return(data.frame(dataframe)) } data=data.frame() data=DbUpdate(data) It works for the first two entries I put in with the same Machine_Name, but when I try to input a third with the same name, I get an "Invalid list argument: all variables should have the same length" error. Can anyone tell me what I'm doing wrong? -- View this message in context: http://r.789695.n4.nabble.com/Classify-User-Input-with-Unique-Identification-Numbers-tp4722458.html Sent from the datatable-help mailing list archive at Nabble.com. From shortlifeplaymore at gmail.com Tue Jul 5 17:36:46 2016 From: shortlifeplaymore at gmail.com (IGGYANFAN) Date: Tue, 5 Jul 2016 08:36:46 -0700 (PDT) Subject: [datatable-help] conditional deleting elements and highlight some of them in a matrix in R Message-ID: <1467733006287-4722497.post@n4.nabble.com> hello, I am a worker in biochemistry filed and get used to do stat by SPSS and SAS and I am totally new in R . I searched a hand by hand tutorial and had done my first correlation analysis and now I have a 252*84 matrix like this which contains results. Since the matrix is really too big to deal it with excel and find significant P values etc, I am thinking about to at first delete the elements in this matrix,ai,j, in which i=3 * j, and j = 1:84 and then I would like to highlight some parts the matrix, or the output of R. In short, I am thinking about to color elements meet aij lower than 0.10 (significant Ps)as red, in which i belong to {2, 5, 8, 11??83}. I tried look at book and search for available codes, However, i really do not know how to put "for" in matrix[-i, -j] and, OK, the right way to use. Could anyone be so nice teach me? Many thanks. -- View this message in context: http://r.789695.n4.nabble.com/conditional-deleting-elements-and-highlight-some-of-them-in-a-matrix-in-R-tp4722497.html Sent from the datatable-help mailing list archive at Nabble.com. From suttoncarl at ymail.com Mon Jul 18 05:43:23 2016 From: suttoncarl at ymail.com (carlsutton) Date: Sun, 17 Jul 2016 20:43:23 -0700 (PDT) Subject: [datatable-help] calculating proportions on 192 column data table grouped by one column Message-ID: <1468813403749-4722828.post@n4.nabble.com> I can do the calculation on a couple columns, but how do I automate this for 192 column data table? # calculating proportion for column variables library(data.table) a <- rep(1:5, 2) b <- sample(20:50, size = 10, replace = TRUE) c <- sample(80:130, size = 10, replace = TRUE) dt1 <- data.table(a,b,c) dt1 d <- sum(dt1$b) e <- sum(dt1$c) proportion_b <- dt1$b/d proportion_c <- dt1$c/e proportion_b proportion_c dt_manipulated <- data.table(dt1,proportion_b, proportion_c) dt_manipulated # now an attempt to add column proportions to the data table dt2 <- dt1[, `:=` (proportion = b/sum(b), proportion = c/sum(c))] identical(dt_manipulated,dt2) # Nice that this works, but I sure do NOT want to do this for 191 columns of data! # My instinct is to use lapply, but how do I define the column to divide by column sum??? ----- Carl Sutton -- View this message in context: http://r.789695.n4.nabble.com/calculating-proportions-on-192-column-data-table-grouped-by-one-column-tp4722828.html Sent from the datatable-help mailing list archive at Nabble.com. From francois.morneau at ign.fr Wed Jul 27 11:22:09 2016 From: francois.morneau at ign.fr (=?UTF-8?Q?Fran=c3=a7ois_Morneau?=) Date: Wed, 27 Jul 2016 11:22:09 +0200 Subject: [datatable-help] calculating proportions on 192 column data table grouped by one column In-Reply-To: <1468813403749-4722828.post@n4.nabble.com> References: <1468813403749-4722828.post@n4.nabble.com> Message-ID: Hello Carl, Will dt1[, lapply(.SD, function(x) x / sum(x))] return what you want ? Regards, Fran?ois Le 18/07/2016 ? 05:43, carlsutton a ?crit : > I can do the calculation on a couple columns, but how do I automate this for > 192 column data table? > > # calculating proportion for column variables > library(data.table) > a <- rep(1:5, 2) > b <- sample(20:50, size = 10, replace = TRUE) > c <- sample(80:130, size = 10, replace = TRUE) > dt1 <- data.table(a,b,c) > dt1 > d <- sum(dt1$b) > e <- sum(dt1$c) > proportion_b <- dt1$b/d > proportion_c <- dt1$c/e > proportion_b > proportion_c > dt_manipulated <- data.table(dt1,proportion_b, proportion_c) > dt_manipulated > # now an attempt to add column proportions to the data table > dt2 <- dt1[, `:=` (proportion = b/sum(b), proportion = c/sum(c))] > identical(dt_manipulated,dt2) > # Nice that this works, but I sure do NOT want to do this for 191 columns > of data! > # My instinct is to use lapply, but how do I define the column to divide by > column sum??? > > > > > > ----- > Carl Sutton > -- > View this message in context: http://r.789695.n4.nabble.com/calculating-proportions-on-192-column-data-table-grouped-by-one-column-tp4722828.html > Sent from the datatable-help mailing list archive at Nabble.com. > _______________________________________________ > datatable-help mailing list > datatable-help at lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help From Noa.Kay at kingcounty.gov Wed Jul 27 19:39:28 2016 From: Noa.Kay at kingcounty.gov (KayN) Date: Wed, 27 Jul 2016 10:39:28 -0700 (PDT) Subject: [datatable-help] Fix Invalid Variable Names Message-ID: <1469641168887-4723196.post@n4.nabble.com> I am reading in a Stata dataset into R which has variable names that are invalid in R (they begin with an underscore). Is there a way to change the invalid variable names in R? Thank you! -- View this message in context: http://r.789695.n4.nabble.com/Fix-Invalid-Variable-Names-tp4723196.html Sent from the datatable-help mailing list archive at Nabble.com. From Noa.Kay at kingcounty.gov Wed Jul 27 19:45:49 2016 From: Noa.Kay at kingcounty.gov (KayN) Date: Wed, 27 Jul 2016 10:45:49 -0700 (PDT) Subject: [datatable-help] Fix Invalid Variable Names In-Reply-To: <1469641168887-4723196.post@n4.nabble.com> References: <1469641168887-4723196.post@n4.nabble.com> Message-ID: <1469641549892-4723198.post@n4.nabble.com> I was using the "readstata13" to read in the stata dataset. I'm open to suggestions that might be able to handle invalid datanames better but they need to be able to read in at least Stata version 13. -- View this message in context: http://r.789695.n4.nabble.com/Fix-Invalid-Variable-Names-tp4723196p4723198.html Sent from the datatable-help mailing list archive at Nabble.com. From MEC at stowers.org Wed Jul 27 21:38:22 2016 From: MEC at stowers.org (Cook, Malcolm) Date: Wed, 27 Jul 2016 19:38:22 +0000 Subject: [datatable-help] Fix Invalid Variable Names In-Reply-To: <1469641168887-4723196.post@n4.nabble.com> References: <1469641168887-4723196.post@n4.nabble.com> Message-ID: This is not really a datatable issue. Anyway, what is the error you get when you try? > -----Original Message----- > From: datatable-help-bounces at lists.r-forge.r-project.org [mailto:datatable- > help-bounces at lists.r-forge.r-project.org] On Behalf Of KayN > Sent: Wednesday, July 27, 2016 12:39 PM > To: datatable-help at lists.r-forge.r-project.org > Subject: [datatable-help] Fix Invalid Variable Names > > I am reading in a Stata dataset into R which has variable names that are > invalid in R (they begin with an underscore). Is there a way to change the > invalid variable names in R? > > Thank you! > > > > -- > View this message in context: http://r.789695.n4.nabble.com/Fix-Invalid- > Variable-Names-tp4723196.html > Sent from the datatable-help mailing list archive at Nabble.com. > _______________________________________________ > datatable-help mailing list > datatable-help at lists.r-forge.r-project.org > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/datatable-help From Noa.Kay at kingcounty.gov Wed Jul 27 21:33:20 2016 From: Noa.Kay at kingcounty.gov (KayN) Date: Wed, 27 Jul 2016 12:33:20 -0700 (PDT) Subject: [datatable-help] Fix Invalid Variable Names In-Reply-To: References: <1469641168887-4723196.post@n4.nabble.com> Message-ID: <1469648000248-4723216.post@n4.nabble.com> Thanks for the tips, all. I've been redirected to another list that should be the correct place to ask about these issues. -- View this message in context: http://r.789695.n4.nabble.com/Fix-Invalid-Variable-Names-tp4723196p4723216.html Sent from the datatable-help mailing list archive at Nabble.com.