Re: [R] Where did lost variables go
On Mon, 30 Dec 2013 20:42:53 -0500 David Parkhurst wrote: > I have several variables in a data frame that aren't listed by ls() > after I attach that data frame. Where did they go, and how can I > stop the hidden ones from masking the local ones? > Thanks for any help. > David > You really need to offer more information, e.g. a reproducible example that includes just how how moved data into your data frame. As it is, the only reasonable suggestion is to try and find your lost singleton socks, the missing variablee may be hiding with them. Alternatively the lost variables may have taken off to Never Never Land to hang with the Lost Boys. One simple possibility is that the missing variables were actually never read in to the data frame. Have you ever seen those variables in your data frame? Did you try str()? As regards "hidden" and "local," you'll - again - have to be a good deal more explicit. JDougherty __ 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.
Re: [R] Basic misunderstanding, or problem with my installation?
On Tue, 31 Dec 2013 19:51:06 -0500 Gabor Grothendieck wrote: ... > > The assignment operator is TWO characters: a less than sign > immediately followed by a minus sign. Try copying and pasting this: > > x <- 3 > x > Actually, you can use the = sign as well. X = 3 works the same as X <- 3 and uses two fewer keystrokes if you're lazy enough to care about such things -like me. __ 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.
[R] Data parsing question: adding characters within a string of characters
Dear Listserve, I have a data-parsing question for you. I recognize this is more in the domain of PERL/Python, but I don't know those languages! On the other hand, I am pretty good overall with R, so I'd rather get the job done within the R "ecosphere." Here is what I want to do. Consider the following data: string <- "ATCGCCCGTA[AGA]TAACCG" I want to alter string so that it looks like this: ATCGCCCGTA[A][G][A]TAACCG In other words, I want to design a piece of code that will scan a character string, find bracketed groups of characters, break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string. The lengths of the character strings enclosed by a bracket will vary, but in every case, I want to do the same thing: break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string. So, for example, another string may look like this: string2 <- "ATTATACGCA[AAATGA]GCTA[AT]GCATTA" I want to alter string so that it looks like this: "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" Thank you all in advance and have a great 2014! --- Josh Banta, Ph.D Assistant Professor Department of Biology The University of Texas at Tyler Tyler, TX 75799 Tel: (903) 565-5655 http://plantevolutionaryecology.org [[alternative HTML version deleted]] __ 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.
Re: [R] How to verify char variables contain at least one value
Hi Jim, Thank you, it works indeed :) Luca 2014/1/2 Jim Lemon > On 01/02/2014 05:17 PM, Luca Meyer wrote: > >> Happy new year fellows, >> >> I am trying to do something I believe should be fairly straightforward but >> I cannot find my way out. >> >> My dataset d2 is 26 rows by 245 columns, exclusively char variables. I >> would like to check whether at least one column from V13 till V239 (they >> are in numerical sequence) has been filled in, so I try >> >> d2$check<- c(d2$V13:d2$V239) >> >> and/or >> >> d2$check<- paste(d2$V13:d2$V239,sep="") >> >> but I get (translated from Italian): >> >> Error in d2$V13:d2$V239 : argument NA/NaN >> >> I have tried nchar but the same error occurs. I have also tried to run the >> above functions on a smaller variable subset (V13, V14, V15, see below for >> details) just to double check in case some variable would erroneously be >> in >> another format, but the same occur. >> >> d2$V13 >>> >> [1] """""" >> """""""da -5.1% a -10%" >> "" >> [9] """""" >> """""""" >> "" >> [17] """""" >> """""""" >> "" >> [25] """" >> >>> d2$V14 >>> >> [1] "" "" "" >> "" "" "" "da -10.1% a >> -15%" >> "" >> [9] "" "" "" >> "" "" "" "" >> "" >> [17] "" "" "" >> "" "" "" "" >> "" >> [25] "" "" >> >>> d2$V15 >>> >> [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" >> "" "" "" >> >> Can anyone suggest an alternative function for me to create a variable >> that >> checks whether there is at least one value for each of the 26 records I >> need to analyze? >> >> Hi Luca, > Perhaps you are looking for something like this: > > d2check<-unlist(apply(as.matrix(d2[,paste("V",13:239,sep="")]),1,nchar)) > # to test for any non empty rows > any(d2check) > > Jim > > [[alternative HTML version deleted]] __ 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.
Re: [R] Where did lost variables go, with example
Hi you are confusing yourself and maybe other audience. With ls() you list objects in your environment (usually stored in .RData file) and loaded with starting R. Let me guess. You probably have 2 data frames All8 and All8Sites. They have some variables inside and you can see structure of any object by str str(All8) you can see names of these variables by names names(All8) you can use those variables by e.g. All8Sites$X You probably managed somehow to save variables from data.frame to independent objects in your environment, which can be confusing. Maybe it is time to read R-intro which is located in doc folder of your R installation. Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of David Parkhurst > Sent: Tuesday, December 31, 2013 5:39 PM > To: Duncan Murdoch; r-help@r-project.org > Subject: Re: [R] Where did lost variables go, with example > > Thank you. I've tried what you're suggesting, at an earlier suggestion > from another respondent, and I don't find my variable in any of lists > ls() through ls(7). > > I'm just going back to using R after being away from statistics for > several years. I'm thinking I might uninstall R, then reinstall it, > and redo my work so far (I've kept the commands elsewhere), and avoid > using "attach," as someone else has suggested. > > David > On 12/31/2013 11:32 AM, Duncan Murdoch wrote: > > On 13-12-31 9:48 AM, David Parkhurst wrote: > >> Two or three respondents asked for an example of my problem. Here's > >> what's happening to me now. I can't reproduce how I got to this > >> point, > >> though: > >> > >> > ls() > >> [1] "All8" "All8Sites" "A" "B" "C" "i" "n" "D" "F" > >> > X > >> Error: object 'X' not found > >> > attach(All8Sites) > >> > ls() > >> [1] "All8" "All8Sites" "A" "B" "C" "i" "n" "D" "F" > >> > >> > >> "X" is one of the variables in the data frame I attached in the > third > >> command above, but it's not listed by >ls(). If I enter > X now, > its > >> values ARE listed, but it's hiding somewhere. What is happening > here? > >> How can I get the variables in that data frame listed when I attach > it? > > > > Use search() to see the search list. Your dataframe will likely be > in > > position 2. Use ls(2) to see the variables there. > > > > Duncan Murdoch > > > > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] Data parsing question: adding characters within a string of characters
On 14-01-01 10:55 PM, Joshua Banta wrote: Dear Listserve, I have a data-parsing question for you. I recognize this is more in the domain of PERL/Python, but I don't know those languages! On the other hand, I am pretty good overall with R, so I'd rather get the job done within the R "ecosphere." Here is what I want to do. Consider the following data: string <- "ATCGCCCGTA[AGA]TAACCG" I want to alter string so that it looks like this: ATCGCCCGTA[A][G][A]TAACCG In other words, I want to design a piece of code that will scan a character string, find bracketed groups of characters, break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string. The lengths of the character strings enclosed by a bracket will vary, but in every case, I want to do the same thing: break up each character within the bracket into its own individual bracketed character, and then put the group of individually bracketed characters back into the character string. So, for example, another string may look like this: string2 <- "ATTATACGCA[AAATGA]GCTA[AT]GCATTA" I want to alter string so that it looks like this: "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" R is fine for that sort of operation, using regular expressions for matching and sub() or gsub() for substitution. For example, this code finds all the bracketed strings of 1 or more ATCG letters: matches <- gregexpr("[[][ATCG]+]", string) In the result, which looks like this for your example string, [[1]] [1] 11 attr(,"match.length") [1] 5 attr(,"useBytes") [1] TRUE the 11 is the start of the bracketed expression, the 5 is the length of the match. (There may be other starts and lengths if there are multiple bracketed expressions.) So use substr to extract the matches. You need to be a little careful putting the string back together after adding the extra brackets, because `substr<-` won't replace a string with one of a different length. I use this version instead: `mysubstr<-` <- function(x, start, stop, value) paste0(substr(x, 1, start-1), value, substr(x, stop+1, nchar(x)) I'll leave the details of the substitutions to you... Duncan Murdoch __ 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.
Re: [R] Data parsing question: adding characters within a string of characters
On Wed, Jan 1, 2014 at 10:55 PM, Joshua Banta wrote: > Dear Listserve, > > I have a data-parsing question for you. I recognize this is more in the > domain of PERL/Python, but I don't know those languages! On the other hand, I > am pretty good overall with R, so I'd rather get the job done within the R > "ecosphere." > > Here is what I want to do. Consider the following data: > > string <- "ATCGCCCGTA[AGA]TAACCG" > > I want to alter string so that it looks like this: > > ATCGCCCGTA[A][G][A]TAACCG > > In other words, I want to design a piece of code that will scan a character > string, find bracketed groups of characters, break up each character within > the bracket into its own individual bracketed character, and then put the > group of individually bracketed characters back into the character string. > The lengths of the character strings enclosed by a bracket will vary, but in > every case, I want to do the same thing: break up each character within the > bracket into its own individual bracketed character, and then put the group > of individually bracketed characters back into the character string. > > So, for example, another string may look like this: > > string2 <- "ATTATACGCA[AAATGA]GCTA[AT]GCATTA" > > I want to alter string so that it looks like this: > > "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" > Here is a one line solution: library(gsubfn) > gsubfn("\\[([^]]+)\\]", ~ paste(paste0("[", strsplit(x, "")[[1]], "]"), > collapse = ""), string) [1] "ATCGCCCGTA[A][G][A]TAACCG" > > gsubfn("\\[([^]]+)\\]", ~ paste(paste0("[", strsplit(x, "")[[1]], "]"), > collapse = ""), string2) [1] "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" __ 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.
Re: [R] Where did lost variables go, with example
On 31 Dec 2013, at 17:32 , Duncan Murdoch wrote: > On 13-12-31 9:48 AM, David Parkhurst wrote: >> Two or three respondents asked for an example of my problem. Here's >> what's happening to me now. I can't reproduce how I got to this point, >> though: >> >> > ls() >> [1] "All8" "All8Sites" "A" "B" "C" "i" "n" "D" "F" >> > X >> Error: object 'X' not found >> > attach(All8Sites) >> > ls() >> [1] "All8" "All8Sites" "A" "B" "C" "i" "n" "D" "F" >> >> >> "X" is one of the variables in the data frame I attached in the third >> command above, but it's not listed by >ls(). If I enter > X now, its >> values ARE listed, but it's hiding somewhere. What is happening here? >> How can I get the variables in that data frame listed when I attach it? > > Use search() to see the search list. Your dataframe will likely be in > position 2. Use ls(2) to see the variables there. Or ls("All8Sites"). Notice, by the way, that this is subtly but importantly different from ls(All8Sites). E.g., > attach(airquality) > ls(2) [1] "Day" "Month" "Ozone" "Solar.R" "Temp""Wind" > ls(airquality) [1] "Day" "Month" "Ozone" "Solar.R" "Temp""Wind" > search() [1] ".GlobalEnv""airquality""package:stats" [4] "package:graphics" "package:grDevices" "package:utils" [7] "package:datasets" "package:methods" "Autoloads" [10] "package:base" > ls("airquality") [1] "Day" "Month" "Ozone" "Solar.R" "Temp""Wind" > rm(Month, pos=2) > ls(airquality) [1] "Day" "Month" "Ozone" "Solar.R" "Temp""Wind" > ls("airquality") [1] "Day" "Ozone" "Solar.R" "Temp""Wind" > detach() > ls("airquality") Error in as.environment(pos) : no item called "airquality" on the search list -pd > > Duncan Murdoch > > __ > 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. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ 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.
Re: [R] Data parsing question: adding characters within a string of characters
Hi Joshua This is one way to do it. Not sure if it this is an efficient implementation for your needs; it depends on the size of your data. string1 <- "ATCGCCCGTA[AGA]TAACCG" string2 <- "ATTATACGCA[AAATGA]GCTA[AT]GCATTA" foo <- function(genes){ mypaste <- function(x) paste("[", paste(x, collapse = "]["), "]", sep = "") tmp <- strsplit(genes, "[[:punct:]]")[[1]] str <- gregexpr("\\[", genes)[[1]] stp <- gregexpr("\\]", genes)[[1]] tmp2 <- substring(genes, str + 1, stp - 1) ndx <- match(tmp2, tmp) tmp[ndx] <- lapply(strsplit(tmp2, ""), mypaste) result <- paste(tmp, collapse = "") return(result) } > foo(string2) [1] "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" > foo(string1) [1] "ATCGCCCGTA[A][G][A]TAACCG" > Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance & Modeling Technology & Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Joshua Banta > Sent: 2. januar 2014 04:56 > To: R Help > Subject: [R] Data parsing question: adding characters within a string of > characters > > Dear Listserve, > > I have a data-parsing question for you. I recognize this is more in the domain > of PERL/Python, but I don't know those languages! On the other hand, I am > pretty good overall with R, so I'd rather get the job done within the R > "ecosphere." > > Here is what I want to do. Consider the following data: > > string <- "ATCGCCCGTA[AGA]TAACCG" > > I want to alter string so that it looks like this: > > ATCGCCCGTA[A][G][A]TAACCG > > In other words, I want to design a piece of code that will scan a character > string, find bracketed groups of characters, break up each character within > the bracket into its own individual bracketed character, and then put the > group of individually bracketed characters back into the character string. The > lengths of the character strings enclosed by a bracket will vary, but in every > case, I want to do the same thing: break up each character within the bracket > into its own individual bracketed character, and then put the group of > individually bracketed characters back into the character string. > > So, for example, another string may look like this: > > string2 <- "ATTATACGCA[AAATGA]GCTA[AT]GCATTA" > > I want to alter string so that it looks like this: > > "ATTATACGCA[A][A][A][T][G][C][C][C][C][A]GCTA[A][T]GCATTA" > > Thank you all in advance and have a great 2014! > > --- > Josh Banta, Ph.D > Assistant Professor > Department of Biology > The University of Texas at Tyler > Tyler, TX 75799 > Tel: (903) 565-5655 > http://plantevolutionaryecology.org > > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
[R] Create a unique group id
I have a following sample data frame. How can I create a group id of column and b and to obtain column c? a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1 4 2 1 4 2 2 5 2 2 5 2 2 5 2 2 5 [[alternative HTML version deleted]] __ 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.
[R] Discrete-continuous equation system in R
Hi all, I want to estimate an equation system with 3 nonlinear continuous equations and one discrete choice (using multinomial logit for the latter). For the nonlinear continuous equations, function nlsystemfit {systemfit} seems to be appropriate. But what's about the discrete choice? Its error component has a logistic distribution. Can it still be incorporated in the equation system? Or can/must the error component be treated in some way to be incorporated? I cannot find a reference to discrete choices in the systemfit package description nor somewhere else. Reinhard Hössinger __ 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.
Re: [R] Create a unique group id
Hi Your question was formated in HTML and therefore came scrammbled. Post in plain text. And preferably use dput for posting data. Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Norbi Gurracho > Sent: Thursday, January 02, 2014 12:33 PM > To: r-help@r-project.org > Subject: [R] Create a unique group id > > I have a following sample data frame. How can I create a group id of > column and b and to obtain column c? ab c 1 1 1 1 > 1 > 1 1 1 1 1 2 2 1 2 2 1 2 2 1 > 3 3 1 > 3 3 1 3 3 2 1 4 2 1 4 2 1 > 4 2 2 > 5 2 2 5 2 2 5 2 2 5 > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] Create a unique group id
Hi, Try: dat <- read.table(text="a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1 4 2 1 4 2 2 5 2 2 5 2 2 5 2 2 5",sep="",header=TRUE) within(dat, d <- as.numeric(factor(paste(a,b),labels=1:5))) A.K. On Thursday, January 2, 2014 8:27 AM, Norbi Gurracho wrote: I have a following sample data frame. How can I create a group id of column and b and to obtain column c? a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1 4 2 1 4 2 2 5 2 2 5 2 2 5 2 2 5 [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] How to remove rows in a matrix having 0 as value in columns per condition
Hi,It is not very clear. data1 <- read.table("PGRTvsPDGRT_frags.txt",header=TRUE,stringsAsFactors=FALSE) mat1<- as.matrix(data1[,-1]) row.names(mat1)<- data1[,1] res <- mat1[apply(mat1,1,function(x) all(x[1:6]!=0) & all(x[7:12]!=0)),] sum(rowSums(!res)>0) #[1] 0 #or #depending upon what you want res1 <- mat1[apply(mat1,1,function(x) all(x[1:6]!=0) | all(x[7:12]!=0)),] dim(res1) #[1] 12750 12 A.K. On Thursday, January 2, 2014 7:47 AM, Vivek Das wrote: Dear Users, I have few queries. I am having a matrix with some counts. there are 2 conditions for each. So I have a matrix with 12 columns with counts. First column is the id and next 6 columns are one condition and the second 6 columns are another condition. I want to remove the rows where each condition is having one 0 column. So for a rows if in both the conditions have one single 0 (which means each condition is having a 0 value) then that row is removed. How can we do that. I was doing like this earlier but we are left with some rows. data1<- read.table("~/Desktop/Bonn_New_Pas_algo_data/results_30092013/edgeR_24122013/PGRTvsPDGRT/PGRTvsPDGRT_frags.txt",header=TRUE,stringsAsFactors=FALSE) mat1<- as.matrix(data1[,-1]) row.names(mat1)<- data1[,1] test <- apply(mat1, 1,function(x) all(x[1:6]==0) | all(x[7:12]==0) ) test1 <- mat1[!test,] But this does not seem correct as I am having some rows like XLOC_004048 26.0133 0 0 0 0 232.296 2.676 8.21482 2.61507 0 0 0 XLOC_004050 0 1 4 36 20 0 0 2 1 0 1 9 This should not be there. Even if both condition together is having one column as zero in each condition in a row then it should be removed. but here we can see more than one column is having 0 values in both condition and still it is there. The the matrix I am working upon is in attachment. Can anyone give any suggestions -- Vivek Das __ 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.
[R] compare two rows in same column in data farme
Hi, I would like to compare row data in the same column through a data frame and remove all rows that do not fit the criteria. for example if I have the following data frame: line start A1 21 A2 22 A3 23 B4 19 B2 24 B6 12 I would like to compare the 'start' value of each line to the value of next line (22-21,23-22,19-23,24-19,12-24) and if it is smaller then to remove the line so that at the end I would get line start A1 21 A2 22 A3 23 B2 24 Thanks, -- \m/ [[alternative HTML version deleted]] __ 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.
Re: [R] compare two rows in same column in data farme
Hi, May be this helps: dat1 <- read.table(text="line start A1 21 A2 22 A3 23 B4 19 B2 24 B6 12",sep="",header=TRUE,stringsAsFactors=FALSE) dat1[c(TRUE,diff(dat1[,2]) >0 ),] # line start #1 A1 21 #2 A2 22 #3 A3 23 #5 B2 24 A.K. On Thursday, January 2, 2014 10:54 AM, raz wrote: Hi, I would like to compare row data in the same column through a data frame and remove all rows that do not fit the criteria. for example if I have the following data frame: line start A1 21 A2 22 A3 23 B4 19 B2 24 B6 12 I would like to compare the 'start' value of each line to the value of next line (22-21,23-22,19-23,24-19,12-24) and if it is smaller then to remove the line so that at the end I would get line start A1 21 A2 22 A3 23 B2 24 Thanks, -- \m/ [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Create a unique group id
Hi, Also, to make it general: vec1 <- with(dat,paste(a,b)) within(dat,d <- as.numeric(factor(vec1,labels=seq(length(unique(vec1)) #or within(dat,d <- match(vec1,unique(vec1))) #or within(dat,d<- as.numeric(interaction(a,b))) #ids are unique, not in the same order A.K. On Thursday, January 2, 2014 9:30 AM, arun wrote: Hi, Try: dat <- read.table(text="a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1 4 2 1 4 2 2 5 2 2 5 2 2 5 2 2 5",sep="",header=TRUE) within(dat, d <- as.numeric(factor(paste(a,b),labels=1:5))) A.K. On Thursday, January 2, 2014 8:27 AM, Norbi Gurracho wrote: I have a following sample data frame. How can I create a group id of column and b and to obtain column c? a b c 1 1 1 1 1 1 1 1 1 1 2 2 1 2 2 1 2 2 1 3 3 1 3 3 1 3 3 2 1 4 2 1 4 2 1 4 2 2 5 2 2 5 2 2 5 2 2 5 [[alternative HTML version deleted]] __ 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. __ 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.
[R] Any R-package geared towards Endorsement Frequencies?
Happy New Year everyone, I need some help figuring out if there is an R package tailored towards endorsement frequencies. Would y'all here know of any such packages that they would recommend I use? Thanks! Lily If it doesn't challenge you, it doesn't change you - Fred DeVito [[alternative HTML version deleted]] __ 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.
Re: [R] Any R-package geared towards Endorsement Frequencies?
Hi Lila, You will probably have to be more specific. What exactly do you want to do? Have you looked at http://cran.r-project.org/web/views/ ? Best, Ista On Thu, Jan 2, 2014 at 9:59 AM, Lila Lorne wrote: > Happy New Year everyone, > > I need some help figuring out if there is an R package tailored towards > endorsement frequencies. Would y'all here know of any such packages that > they would recommend I use? > > Thanks! > > Lily > > > > > > If it doesn't challenge you, it doesn't change you - Fred DeVito > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] seq_len and loops
On 01/01/2014 07:36 PM, William Dunlap wrote: 2. However, Bill (and Henrik) raised the question of replacing '1' with '1L'; I understand the meaning of that, but does it matter (in practice)? On 12/22/2013 06:57 PM, William Dunlap wrote: for (i in seq_len(x - 1) + 1) should be efficient and safe. Oops, not safe when x is 0. Also, the '+ 1' should be '+ 1L' to get the same answer as seq_len(x)[-1]. It depends what your practice involves. seq_len(n)[-1], 2:n, and seq_len(n-1)+1L all produce an integer vector (if 0 Thanks Bill; I am aware of these details since my days as a successful Fortran programmer;)! I guess this background is what makes me worry about the apparently careless choice of variable type that I can get away with in R. If you prefer a sequence to be numeric, then use as.numeric(seq_len(n)), as.numeric(seq_len(n))[-1], or seq_len(n)+1 when making it. If you prefer integers, then use seq_len(n), seq_len(n)[-1], or seq_len(n)+1L. If you don't care, do whatever seems easiest at the time. if (x > 1){ for (x in 2:x){ ... is the easiest, most effective, and most easy-to-understand. The dangerous part of that idiom is what you do in the 'else' part of the 'if' statement. Do both clauses make objects with the same names and types? I mildly prefer avoiding if statements because it makes reasoning about the results of the code more complicated. I get your point; I however never have an 'else' part in this context (if x == 1 I'm already done). Another observation: The 'while (x < n) x <- x + 1' approach is very slow compared to a for loop. Göran Broström Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Göran Broström Sent: Tuesday, December 31, 2013 4:10 PM To: r-help@R-project.org Subject: Re: [R] seq_len and loops Thanks for the answers from Duncan, Bill, Gabor, and Henrik. You convinced me that 1. The solution if (x > 1){ for (x in 2:x){ ... is the easiest, most effective, and most easy-to-understand. 2. However, Bill (and Henrik) raised the question of replacing '1' with '1L'; I understand the meaning of that, but does it matter (in practice)? 3. Noone commented upon i <- 1 while (i < x){ i <- i + 1 ... } I suppose that it means that it is the best solution. Thanks, and Happy New Year 2014! Göran On 12/22/2013 06:57 PM, William Dunlap wrote: for (i in seq_len(x - 1) + 1) should be efficient and safe. Oops, not safe when x is 0. Also, the '+ 1' should be '+ 1L' to get the same answer as seq_len(x)[-1]. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan Murdoch Sent: Saturday, December 21, 2013 3:52 PM To: Göran Broström; R-help@r-project.org Subject: Re: [R] seq_len and loops On 13-12-21 6:50 PM, Duncan Murdoch wrote: On 13-12-21 5:57 PM, Göran Broström wrote: I was recently reminded on this list that "Using 1:ncol() is bad practice (seq_len is designed for that purpose)" (Ripley) This triggers the following question: What is "good practice" for 2:ncol(x)? (This is not a joke; in a recursive situation it often makes sense to perform the calculation for the start value i = 1, then continue with a loop over the rest, "the Fortran way";) I usually use if (ncol(x) > 1) for (i in 2:ncol(x)){ but I can think of for (i in seq_len(x - 1)){ I <- i + 1 and i <- 1 while (i < ncol(x)){ i <- i + 1 What is "good practice" (efficient and safe)? for (i in seq_len(x - 1) + 1) should be efficient and safe. Oops, not safe when x is 0. > A little less efficient, but clearer would be for (i in seq_len(x)[-1]) Duncan Murdoch __ 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. __ 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. __ 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.
Re: [R] Create a unique group id
Thanks Arun. How does code differs if I have a date variable instead of numbers like in column a? I have a sample data in dput output. > dput(mydf) structure(list(a = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), b = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), c = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2010-01-01", "2010-01-02" ), class = "factor")), .Names = c("a", "b", "c", "date"), row.names = c(NA, -16L), class = "data.frame") Thanks > Date: Thu, 2 Jan 2014 08:09:59 -0800 > From: smartpink...@yahoo.com > Subject: Re: [R] Create a unique group id > To: r-help@r-project.org > CC: kum...@hotmail.com > > Hi, > > Also, to make it general: > > vec1 <- with(dat,paste(a,b)) > аwithin(dat,d <- as.numeric(factor(vec1,labels=seq(length(unique(vec1)) > > #or > аwithin(dat,d <- match(vec1,unique(vec1))) > > > #or > within(dat,d<- as.numeric(interaction(a,b))) #ids are unique, not in the same > order > A.K. > > > > > On Thursday, January 2, 2014 9:30 AM, arun wrote: > Hi, > Try: > dat <- read.table(text="aааа bааа c > а1ааа 1ааа 1 > а1ааа 1ааа 1 > а1ааа 1ааа 1 > а1ааа 2ааа 2 > а1ааа 2ааа 2 > а1ааа 2ааа 2 > а1ааа 3ааа 3 > а1ааа 3ааа 3 > а1ааа 3ааа 3 > а2ааа 1ааа 4 > а2ааа 1ааа 4 > а2ааа 1ааа 4 > а2ааа 2ааа 5 > а2ааа 2ааа 5 > а2ааа 2ааа 5 > а2ааа 2ааа 5",sep="",header=TRUE)а > > > а within(dat, d <- as.numeric(factor(paste(a,b),labels=1:5))) > A.K. > > > > On Thursday, January 2, 2014 8:27 AM, Norbi Gurracho > wrote: > I have a following sample data frame. How can I create a group id of column > and b and to obtain column c? aааа bааа c 1ааа 1ааа 1 1ааа 1ааа 1 1ааа 1ааа 1 > 1ааа 2ааа 2 1ааа 2ааа 2 1ааа 2ааа 2 1ааа 3ааа 3 1ааа 3ааа 3 1ааа 3ааа 3 2ааа > 1ааа 4 2ааа 1ааа 4 2ааа 1ааа 4 2ааа 2ааа 5 2ааа 2ааа 5 2ааа 2ааа 5 2ааа 2ааа > 5а ааа ааа аа ааа ааа а > ааа [[alternative HTML version deleted]] > > __ > 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. > __ 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.
Re: [R] Any R-package geared towards Endorsement Frequencies?
I am working with a dataset that is observations of mentors or senior teachers evaluating new or junior teachers in primary classrooms. There are 27 items (5-pt Likert) and I would like to know the proportion of respondents who endorse each response category, including floor and ceiling effects. I have to report on the viability of dropping items and want to look at the data from a couple of different perspectives (going to conduct an EFA next). I perused the packages but didn't find any that fit well for my purposes. I figure EF are routinized somewhere in R, I just need help to find it. Best, Lila On Thu, Jan 2, 2014 at 12:02 PM, Ista Zahn wrote: > Hi Lila, > > You will probably have to be more specific. What exactly do you want > to do? Have you looked at http://cran.r-project.org/web/views/ ? > > Best, > Ista > > On Thu, Jan 2, 2014 at 9:59 AM, Lila Lorne > wrote: > > Happy New Year everyone, > > > > I need some help figuring out if there is an R package tailored towards > > endorsement frequencies. Would y'all here know of any such packages that > > they would recommend I use? > > > > Thanks! > > > > Lily > > > > > > > > > > > > If it doesn't challenge you, it doesn't change you - Fred DeVito > > > > [[alternative HTML version deleted]] > > > > __ > > 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. > -- If it doesn't challenge you, it doesn't change you - Fred DeVito [[alternative HTML version deleted]] __ 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.
Re: [R] Create a unique group id
Hi Norbi, It would be almost the same. vec1 <- with(mydf,paste(b,date)) res <- within(mydf, d <- match(vec1,unique(vec1))) res$d # [1] 1 1 1 2 2 2 3 3 3 4 4 4 5 5 5 5 mydf$date <- as.Date(mydf$date) A.K. On Thursday, January 2, 2014 12:04 PM, Norbi Gurracho wrote: Thanks Arun. How does code differs if I have a date variable instead of numbers like in column a? I have a sample data in dput output. > dput(mydf) structure(list(a = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), b = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("1", "2", "3"), class = "factor"), c = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("1", "2", "3", "4", "5"), class = "factor"), date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("2010-01-01", "2010-01-02" ), class = "factor")), .Names = c("a", "b", "c", "date"), row.names = c(NA, -16L), class = "data.frame") Thanks > Date: Thu, 2 Jan 2014 08:09:59 -0800 > From: smartpink...@yahoo.com > Subject: Re: [R] Create a unique group id > To: r-help@r-project.org > CC: kum...@hotmail.com > > Hi, > > Also, to make it general: > > vec1 <- with(dat,paste(a,b)) > аwithin(dat,d <- as.numeric(factor(vec1,labels=seq(length(unique(vec1)) > > #or > аwithin(dat,d <- match(vec1,unique(vec1))) > > > #or > within(dat,d<- as.numeric(interaction(a,b))) #ids are unique, not in the same > order > A.K. > > > > > On Thursday, January 2, 2014 9:30 AM, arun wrote: > Hi, > Try: > dat <- read.table(text="aааа bааа c > а1ааа 1ааа 1 > а1ааа 1ааа 1 > а1ааа 1ааа 1 > а1ааа 2ааа 2 > а1ааа 2ааа 2 > а1ааа 2ааа 2 > а1ааа 3ааа 3 > а1ааа 3ааа 3 > а1ааа 3ааа 3 > а2ааа 1ааа 4 > а2ааа 1ааа 4 > а2ааа 1ааа 4 > а2ааа 2ааа 5 > а2ааа 2ааа 5 > а2ааа 2ааа 5 > а2ааа 2ааа 5",sep="",header=TRUE)а > > > а within(dat, d <- as.numeric(factor(paste(a,b),labels=1:5))) > A.K. > > > > On Thursday, January 2, 2014 8:27 AM, Norbi Gurracho > wrote: > I have a following sample data frame. How can I create a group id of column > and b and to obtain column c? aааа bааа c 1ааа 1ааа 1 1ааа 1ааа 1 1ааа 1ааа 1 > 1ааа 2ааа 2 1ааа 2ааа 2 1ааа 2ааа 2 1ааа 3ааа 3 1ааа 3ааа 3 1ааа 3ааа 3 2ааа > 1ааа 4 2ааа 1ааа 4 2ааа 1ааа 4 2ааа 2ааа 5 2ааа 2ааа 5 2ааа 2ааа 5 2ааа 2ааа > 5а ааа ааа аа ааа ааа а > ааа [[alternative HTML version deleted]] > > __ > 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. > __ 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.
Re: [R] Any R-package geared towards Endorsement Frequencies?
see ?table and ?prop.table for counts and proportions. For factor analysis I usually use the functions in the psych package (see https://personality-project.org/r/#factoranal) , but there are others including the built in ?factanal function. Additional options are described in the psychometrics task view. Best, Ista On Thu, Jan 2, 2014 at 1:10 PM, Lila Lorne wrote: > I am working with a dataset that is observations of mentors or senior > teachers evaluating new or junior teachers in primary classrooms. There are > 27 > items (5-pt Likert) and I would like to know the proportion of > respondents who endorse each response category, including floor and ceiling > effects. I have to report on the viability of dropping items and want to > look at the data from a couple of different perspectives (going to conduct > an EFA next). > > I perused the packages but didn't find any that fit well for my purposes. I > figure EF are routinized somewhere in R, I just need help to find it. > > Best, > Lila > > On Thu, Jan 2, 2014 at 12:02 PM, Ista Zahn wrote: > >> Hi Lila, >> >> You will probably have to be more specific. What exactly do you want >> to do? Have you looked at http://cran.r-project.org/web/views/ ? >> >> Best, >> Ista >> >> On Thu, Jan 2, 2014 at 9:59 AM, Lila Lorne >> wrote: >> > Happy New Year everyone, >> > >> > I need some help figuring out if there is an R package tailored towards >> > endorsement frequencies. Would y'all here know of any such packages that >> > they would recommend I use? >> > >> > Thanks! >> > >> > Lily >> > >> > >> > >> > >> > >> > If it doesn't challenge you, it doesn't change you - Fred DeVito >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > 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. >> > > > > -- > If it doesn't challenge you, it doesn't change you - Fred DeVito > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
Re: [R] For loop for frequency counting
Hi, May be this helps: var1 <- ave(seq_along(fam),fam,FUN=length) names(var1) <- fam var1 #2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 #4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 #or table(fam)[as.character(fam)] #fam #2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 #4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 fam1 <- c(fam,2) var2 <- table(fam1)[as.character(fam1)] names(dimnames(var2)) <- NULL var2 #2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 2 #5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 5 A.K. fam <- sort(rep(2:5, 4)) I want to create a new variable of the same length as fam, that stores the number of observations of each value. Another way to think about this would be like table(fam) but with the results of table(fam) linked to each record. I tried: for (i in unique(fam)) { num <- sum(fam == i) } but it doesn't work, I think because of the i being the value itself rather than a handle? Idk. How would I do this? Thank you :) __ 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.
Re: [R] looping function through list
Hi, May be this helps: set.seed(42) output1 <- list(list(matrix(0,8,11),matrix(0,8,11)), list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10))) library(emdist) sapply(output1,function(x) {emd2d(x[[seq_along(x)[1]]],x[[seq_along(x)[2]]]) }) #[1] NaN -6.089909 A.K. I'm trying to apply a function to a list using rapply but I'm having trouble doing so. I'm trying to calculate the earth-movers distance using the emdist package. Every index in the list has two subindices. I want to calculate the earth-movers distance for these subindices iteratively. An example of the list: head(output) [[1]] [[1]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[1]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[2]] [[2]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.549675 5.834462 5.401988 5.933774 [2,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.304306 5.834462 5.401988 5.933774 [3,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.485151 5.834462 5.401988 5.933774 [4,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [5,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [6,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [7,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [8,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [,11] [1,] 6.549675 [2,] 6.304306 [3,] 6.485151 [4,] 6.790983 [5,] 7.102360 [6,] 7.211278 [7,] 7.211278 [8,] 7.164059 [[2]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 6.886406 8.814196 10.11709 10.42109 9.935707 11.30645 12.24151 11.38414 10.95166 [2,] 6.641038 8.568828 9.87172 10.17572 9.690339 11.06109 11.99614 11.13877 10.70629 [3,] 6.821883 8.749673 10.05257 10.35657 9.871184 11.24193 12.17699 11.31961 10.88714 [4,] 7.127715 9.055504 10.35840 10.66240 10.177015 11.54776 12.48282 11.62545 11.19297 [5,] 7.439092 9.366881 10.66977 10.97378 10.488392 11.85914 12.79420 11.93682 11.50435 [6,] 7.749465 9.677255 10.98015 11.28415 10.798766 12.16951 13.10457 12.24720 11.81472 [7,] 7.783697 9.711487 11.01438 11.31838 10.832998 12.20375 13.13880 12.28143 11.84895 [8,] 7.500790 9.428580 10.73147 11.03548 10.550091 11.92084 12.85590 11.99852 11.56605 [,10] [,11] [1,] 11.48345 12.76095 [2,] 11.23808 12.51558 [3,] 11.41893 12.69643 [4,] 11.72476 13.00226 [5,] 12.03613 13.31364 [6,] 12.34651 13.62401 [7,] 12.38074 13.65824 [8,] 12.09783 13.37534 I have tried combining rapply and do.call in this fashion but it has failed so far: library(emdist) do.call(rbind, rapply(output, function(x,y) emd2d)) The error message I get is: Error in (function (..., deparse.level = 1) : cannot coerce type 'closure' to vector of type 'list' Any ideas? __ 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.
Re: [R] looping function through list
#or mapply(emd2d,sapply(output1,`[`,1),sapply(output1,`[`,2)) #[1] NaN -6.089909 A.K. On Thursday, January 2, 2014 2:33 PM, arun wrote: Hi, May be this helps: set.seed(42) output1 <- list(list(matrix(0,8,11),matrix(0,8,11)), list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10))) library(emdist) sapply(output1,function(x) {emd2d(x[[seq_along(x)[1]]],x[[seq_along(x)[2]]]) }) #[1] NaN -6.089909 A.K. I'm trying to apply a function to a list using rapply but I'm having trouble doing so. I'm trying to calculate the earth-movers distance using the emdist package. Every index in the list has two subindices. I want to calculate the earth-movers distance for these subindices iteratively. An example of the list: head(output) [[1]] [[1]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[1]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[2]] [[2]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.549675 5.834462 5.401988 5.933774 [2,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.304306 5.834462 5.401988 5.933774 [3,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.485151 5.834462 5.401988 5.933774 [4,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [5,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [6,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [7,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [8,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [,11] [1,] 6.549675 [2,] 6.304306 [3,] 6.485151 [4,] 6.790983 [5,] 7.102360 [6,] 7.211278 [7,] 7.211278 [8,] 7.164059 [[2]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 6.886406 8.814196 10.11709 10.42109 9.935707 11.30645 12.24151 11.38414 10.95166 [2,] 6.641038 8.568828 9.87172 10.17572 9.690339 11.06109 11.99614 11.13877 10.70629 [3,] 6.821883 8.749673 10.05257 10.35657 9.871184 11.24193 12.17699 11.31961 10.88714 [4,] 7.127715 9.055504 10.35840 10.66240 10.177015 11.54776 12.48282 11.62545 11.19297 [5,] 7.439092 9.366881 10.66977 10.97378 10.488392 11.85914 12.79420 11.93682 11.50435 [6,] 7.749465 9.677255 10.98015 11.28415 10.798766 12.16951 13.10457 12.24720 11.81472 [7,] 7.783697 9.711487 11.01438 11.31838 10.832998 12.20375 13.13880 12.28143 11.84895 [8,] 7.500790 9.428580 10.73147 11.03548 10.550091 11.92084 12.85590 11.99852 11.56605 [,10] [,11] [1,] 11.48345 12.76095 [2,] 11.23808 12.51558 [3,] 11.41893 12.69643 [4,] 11.72476 13.00226 [5,] 12.03613 13.31364 [6,] 12.34651 13.62401 [7,] 12.38074 13.65824 [8,] 12.09783 13.37534 I have tried combining rapply and do.call in this fashion but it has failed so far: library(emdist) do.call(rbind, rapply(output, function(x,y) emd2d)) The error message I get is: Error in (function (..., deparse.level = 1) : cannot coerce type 'closure' to vector of type 'list' Any ideas? __ 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.
Re: [R] R crashes with memory errors on a 256GB machine (and system shoes only 60GB usage)
Xebar Saram gmail.com> writes: > > Hi All, > > I have a terrible issue i cant seem to debug which is halting my work > completely. I have R 3.02 installed on a linux machine (arch linux-latest) > which I built specifically for running high memory use models. the system > is a 16 core, 256 GB RAM machine. it worked well at the start but in the > recent days i keep getting errors and crashes regarding memory use, such as > "cannot create vector size of XXX, not enough memory" etc > > when looking at top (linux system monitor) i see i barley scrape the 60 GB > of ram (out of 256GB) > > i really don't know how to debug this and my whole work is halted due to > this so any help would be greatly appreciated I'm very sympathetic, but it will be almost impossible to debug this sort of a problem remotely, without a reproducible example. The only guess that I can make, if you *really* are running *exactly* the same code as you previously ran successfully, is that you might have some very large objects hidden away in a saved workspace in a .RData file that's being loaded automatically ... I would check whether gc(), memory.profile(), etc. give sensible results in a clean R session (R --vanilla). Ben Bolker __ 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.
Re: [R] R crashes with memory errors on a 256GB machine (and system shoes only 60GB usage)
Describing the problem would help a lot more. For example, if you were using some of the parallel processing options in R, this can make extra copies of objects and drive memory usage up very quickly. Max On Thu, Jan 2, 2014 at 3:35 PM, Ben Bolker wrote: > Xebar Saram gmail.com> writes: > > > > > Hi All, > > > > I have a terrible issue i cant seem to debug which is halting my work > > completely. I have R 3.02 installed on a linux machine (arch > linux-latest) > > which I built specifically for running high memory use models. the system > > is a 16 core, 256 GB RAM machine. it worked well at the start but in the > > recent days i keep getting errors and crashes regarding memory use, such > as > > "cannot create vector size of XXX, not enough memory" etc > > > > when looking at top (linux system monitor) i see i barley scrape the 60 > GB > > of ram (out of 256GB) > > > > i really don't know how to debug this and my whole work is halted due to > > this so any help would be greatly appreciated > > I'm very sympathetic, but it will be almost impossible to debug > this sort of a problem remotely, without a reproducible example. > The only guess that I can make, if you *really* are running *exactly* > the same code as you previously ran successfully, is that you might > have some very large objects hidden away in a saved workspace in a > .RData file that's being loaded automatically ... > > I would check whether gc(), memory.profile(), etc. give sensible results > in a clean R session (R --vanilla). > > Ben Bolker > > __ > 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. > -- Max [[alternative HTML version deleted]] __ 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.
Re: [R] How to verify char variables contain at least one value
O-ha, sorry, Luca, I mixed up arguments: it shouldn't be "subset" but "select". apply( subset( d2, select = V13:V239), 1, function( x) any( x != "")) should work. "Auf Wiederhören!" ;-) Regards -- Gerrit On Thu, 2 Jan 2014, Luca Meyer wrote: Hi Gerrit, Thank you for the suggestion. Unfortunatedly the line of code you suggest - i.e. apply( subset( d2, subset = V13:V239), 1, function( x) any( x != "")) returns the same error. Any other suggestion? Danke schôn und auf wiederhoren Luca 2014/1/2 Gerrit Eichner Hello, Luca, also a happy new year! It's not quite clear to me what you want to do, but note first that the ":"-operator is a short-cut for seq() with by = 1 (look at ?seq), and that it usually (!) does not work on columns of data frames. Exception: when used for the argument subset of function subset(). Second, you seem to want to check in each row of d2 if there is any entry different from "", right? So, does apply( subset( d2, subset = V13:V239), 1, function( x) any( x != "")) what you want? Hth -- Gerrit On Thu, 2 Jan 2014, Luca Meyer wrote: Happy new year fellows, I am trying to do something I believe should be fairly straightforward but I cannot find my way out. My dataset d2 is 26 rows by 245 columns, exclusively char variables. I would like to check whether at least one column from V13 till V239 (they are in numerical sequence) has been filled in, so I try d2$check <- c(d2$V13:d2$V239) and/or d2$check <- paste(d2$V13:d2$V239,sep="") but I get (translated from Italian): Error in d2$V13:d2$V239 : argument NA/NaN I have tried nchar but the same error occurs. I have also tried to run the above functions on a smaller variable subset (V13, V14, V15, see below for details) just to double check in case some variable would erroneously be in another format, but the same occur. d2$V13 [1] """""" """""""da -5.1% a -10%" "" [9] """""" """""""" "" [17] """""" """""""" "" [25] """" d2$V14 [1] "" "" "" "" "" "" "da -10.1% a -15%" "" [9] "" "" "" "" "" "" "" "" [17] "" "" "" "" "" "" "" "" [25] "" "" d2$V15 [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Can anyone suggest an alternative function for me to create a variable that checks whether there is at least one value for each of the 26 records I need to analyze? Thank you in advance, Luca [[alternative HTML version deleted]] __ 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.__ 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.
Re: [R] Discrete-continuous equation system in R
Dear Reinhard On 2 January 2014 14:12, Reinhard Hössinger wrote: > I want to estimate an equation system with 3 nonlinear continuous > equations and one discrete choice (using multinomial logit for the > latter). For the nonlinear continuous equations, function nlsystemfit > {systemfit} seems to be appropriate. But what's about the discrete > choice? Its error component has a logistic distribution. Can it still be > incorporated in the equation system? Or can/must the error component be > treated in some way to be incorporated? I cannot find a reference to > discrete choices in the systemfit package description nor somewhere > else. I guess that the econometric estimation of this type of model has not been implemented in any ready-to-use software package. Hence, you probably need to derive the log-likelihood function of this model, implement this function (and preferably also the derivatives/gradients with respect to the parameters), and maximize this log-likelihood function, e.g. with the R package "maxLik" (http://maxlik.org/). Best regards, Arne -- Arne Henningsen http://www.arne-henningsen.name __ 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.
Re: [R] looping function through list
HI, I tested it on R 3.0.2 console (linux) and also on Rstudio Version 0.98.490. It seems alright. A.K. Thanks for this. I am trying to run the code you posted but Rstudio keeps crashing. I am trying to run it on the example output1 since it's small but that crashes as well. On Thursday, January 2, 2014 2:36 PM, arun wrote: #or mapply(emd2d,sapply(output1,`[`,1),sapply(output1,`[`,2)) #[1] NaN -6.089909 A.K. On Thursday, January 2, 2014 2:33 PM, arun wrote: Hi, May be this helps: set.seed(42) output1 <- list(list(matrix(0,8,11),matrix(0,8,11)), list(matrix(rnorm(80),8,10),matrix(rnorm(80),8,10))) library(emdist) sapply(output1,function(x) {emd2d(x[[seq_along(x)[1]]],x[[seq_along(x)[2]]]) }) #[1] NaN -6.089909 A.K. I'm trying to apply a function to a list using rapply but I'm having trouble doing so. I'm trying to calculate the earth-movers distance using the emdist package. Every index in the list has two subindices. I want to calculate the earth-movers distance for these subindices iteratively. An example of the list: head(output) [[1]] [[1]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[1]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 [5,] 0 0 0 0 0 0 0 0 0 0 0 [6,] 0 0 0 0 0 0 0 0 0 0 0 [7,] 0 0 0 0 0 0 0 0 0 0 0 [8,] 0 0 0 0 0 0 0 0 0 0 0 [[2]] [[2]][[1]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.549675 5.834462 5.401988 5.933774 [2,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.304306 5.834462 5.401988 5.933774 [3,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.485151 5.834462 5.401988 5.933774 [4,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [5,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [6,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [7,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [8,] 1.336731 3.264521 4.567414 4.871417 4.386032 5.75678 6.691836 5.834462 5.401988 5.933774 [,11] [1,] 6.549675 [2,] 6.304306 [3,] 6.485151 [4,] 6.790983 [5,] 7.102360 [6,] 7.211278 [7,] 7.211278 [8,] 7.164059 [[2]][[2]] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [1,] 6.886406 8.814196 10.11709 10.42109 9.935707 11.30645 12.24151 11.38414 10.95166 [2,] 6.641038 8.568828 9.87172 10.17572 9.690339 11.06109 11.99614 11.13877 10.70629 [3,] 6.821883 8.749673 10.05257 10.35657 9.871184 11.24193 12.17699 11.31961 10.88714 [4,] 7.127715 9.055504 10.35840 10.66240 10.177015 11.54776 12.48282 11.62545 11.19297 [5,] 7.439092 9.366881 10.66977 10.97378 10.488392 11.85914 12.79420 11.93682 11.50435 [6,] 7.749465 9.677255 10.98015 11.28415 10.798766 12.16951 13.10457 12.24720 11.81472 [7,] 7.783697 9.711487 11.01438 11.31838 10.832998 12.20375 13.13880 12.28143 11.84895 [8,] 7.500790 9.428580 10.73147 11.03548 10.550091 11.92084 12.85590 11.99852 11.56605 [,10] [,11] [1,] 11.48345 12.76095 [2,] 11.23808 12.51558 [3,] 11.41893 12.69643 [4,] 11.72476 13.00226 [5,] 12.03613 13.31364 [6,] 12.34651 13.62401 [7,] 12.38074 13.65824 [8,] 12.09783 13.37534 I have tried combining rapply and do.call in this fashion but it has failed so far: library(emdist) do.call(rbind, rapply(output, function(x,y) emd2d)) The error message I get is: Error in (function (..., deparse.level = 1) : cannot coerce type 'closure' to vector of type 'list' Any ideas? __ 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.
Re: [R] R crashes with memory errors on a 256GB machine (and system shoes only 60GB usage)
Le jeudi 02 janvier 2014 à 09:07 +0200, Xebar Saram a écrit : > Hi All, > > I have a terrible issue i cant seem to debug which is halting my work > completely. I have R 3.02 installed on a linux machine (arch linux-latest) > which I built specifically for running high memory use models. the system > is a 16 core, 256 GB RAM machine. it worked well at the start but in the > recent days i keep getting errors and crashes regarding memory use, such as > "cannot create vector size of XXX, not enough memory" etc > > when looking at top (linux system monitor) i see i barley scrape the 60 GB > of ram (out of 256GB) > > i really don't know how to debug this and my whole work is halted due to > this so any help would be greatly appreciated One important thing to note is that while the memory use may appear to be low, if the memory is fragmented, R may not be able to allocate a *contiguous* memory area for a big vector (you didn't tell us how big it was). In that case, AFAIK the only solution is to restart R (saving the session or objects you want to keep). Regards __ 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.
[R] Help with {tables} package
Dear list, I'm most likely doing something wrong, but I'm getting an error message in tab2 below (tab1 is fine). Any hint is much appreciated. library(tables) set.seed(1) dd <- data.frame(x = rnorm(100), f1 = gl(2, 50, labels = c("A", "B")), f2 = gl(4, 25, labels = c("a", "b", "c", "d")), f3 = as.factor(sample(1:10, 100, replace = T))) tab1 <- tabular((n=1) + Format(digits=1) * ((x) * (Avg. = mean)) + Format(digits=4) * ((Factor(f1) + Factor(f2)) * (Pctn. = Percent('col'))) ~ Justify(c) * (f3 + 1), data = dd) tab1 tab2 <- tabular((n=1) + Format(digits=1) * ((x) * (Avg. = mean)) + Format(digits=4) * ((Factor(f1)) * (Pctn. = Percent('col'))) ~ Justify(c) * (f3 + 1), data = dd) Error in justification[j, ] <- rightjustification : number of items to replace is not a multiple of replacement length Best, Lars. [[alternative HTML version deleted]] __ 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.
Re: [R] How to verify char variables contain at least one value
HI, If I understand correctly, you could also try: set.seed(48) d2 <- as.data.frame(matrix(sample(c("",letters[1:2]),26*245,replace=TRUE),26,245)) d2[3,] <- "" names1 <-paste0("V",13:239) res <- d2[rowSums(d2[,names1]=="") < ncol(d2[,names1]),names1] A.K. On Thursday, January 2, 2014 1:20 AM, Luca Meyer wrote: Happy new year fellows, I am trying to do something I believe should be fairly straightforward but I cannot find my way out. My dataset d2 is 26 rows by 245 columns, exclusively char variables. I would like to check whether at least one column from V13 till V239 (they are in numerical sequence) has been filled in, so I try d2$check <- c(d2$V13:d2$V239) and/or d2$check <- paste(d2$V13:d2$V239,sep="") but I get (translated from Italian): Error in d2$V13:d2$V239 : argument NA/NaN I have tried nchar but the same error occurs. I have also tried to run the above functions on a smaller variable subset (V13, V14, V15, see below for details) just to double check in case some variable would erroneously be in another format, but the same occur. > d2$V13 [1] "" "" "" "" "" "" "da -5.1% a -10%" "" [9] "" "" "" "" "" "" "" "" [17] "" "" "" "" "" "" "" "" [25] "" "" > d2$V14 [1] "" "" "" "" "" "" "da -10.1% a -15%" "" [9] "" "" "" "" "" "" "" "" [17] "" "" "" "" "" "" "" "" [25] "" "" > d2$V15 [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" Can anyone suggest an alternative function for me to create a variable that checks whether there is at least one value for each of the 26 records I need to analyze? Thank you in advance, Luca [[alternative HTML version deleted]] __ 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. __ 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.
[R] Tracking what R actually executes
R 3.0.2 All platforms Colleagues This question is probably conceptual rather than technical and I have not thought out all of the issues yet. Let’s say I have an extensive list of functions and some lines of code that call the functions. I would like to have a record of all the commands that were actually executed. I realize that this could be voluminous but it might be necessary. For example, the code and function might be: ### INPUT: COUNTER <- function(N) for (i in 1:N) cat(“count”, i, “\n”) COUNTER(10) ### OUTPUT: cat(“count”, 1, “\n”) cat(“count”, 2, “\n”) cat(“count”, 3, “\n”) cat(“count”, 4, “\n”) cat(“count”, 5, “\n”) cat(“count”, 6, “\n”) cat(“count”, 7, “\n”) cat(“count”, 8, “\n”) cat(“count”, 9, “\n”) cat(“count”, 10, “\n”) # If I have formulated the question poorly, please do you best to understand the intent. Dennis Dennis Fisher MD P < (The "P Less Than" Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.com __ 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.
Re: [R] Tracking what R actually executes
On 14-01-02 6:05 PM, Fisher Dennis wrote: R 3.0.2 All platforms Colleagues This question is probably conceptual rather than technical and I have not thought out all of the issues yet. Let’s say I have an extensive list of functions and some lines of code that call the functions. I would like to have a record of all the commands that were actually executed. I realize that this could be voluminous but it might be necessary. For example, the code and function might be: ### INPUT: COUNTER <- function(N) for (i in 1:N) cat(“count”, i, “\n”) COUNTER(10) ### OUTPUT: cat(“count”, 1, “\n”) cat(“count”, 2, “\n”) cat(“count”, 3, “\n”) cat(“count”, 4, “\n”) cat(“count”, 5, “\n”) cat(“count”, 6, “\n”) cat(“count”, 7, “\n”) cat(“count”, 8, “\n”) cat(“count”, 9, “\n”) cat(“count”, 10, “\n”) # If I have formulated the question poorly, please do you best to understand the intent. Dennis As far as I know, R doesn't have exactly this built in, but the Rprof() function gives an approximation. It will interrupt the execution at a regular time interval (1/50 sec is the default, I think), and record all functions that are currently active on the execution stack. So tiny little functions could be missed, but bigger ones probably won't be. There are also options to Rprof to give other profiling information, including more detail on execution position (down to the line number), and various measures of memory use. Duncan Murdoch __ 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.
Re: [R] Help with {tables} package
On 14-01-02 5:36 PM, Lars Bishop wrote: Dear list, I'm most likely doing something wrong, but I'm getting an error message in tab2 below (tab1 is fine). Any hint is much appreciated. This was a bug in tables, which I've tracked down. I'll soon upload an update to R-forge, later to CRAN. Look for a version number higher than 0.7.67. Duncan Murdoch library(tables) set.seed(1) dd <- data.frame(x = rnorm(100), f1 = gl(2, 50, labels = c("A", "B")), f2 = gl(4, 25, labels = c("a", "b", "c", "d")), f3 = as.factor(sample(1:10, 100, replace = T))) tab1 <- tabular((n=1) + Format(digits=1) * ((x) * (Avg. = mean)) + Format(digits=4) * ((Factor(f1) + Factor(f2)) * (Pctn. = Percent('col'))) ~ Justify(c) * (f3 + 1), data = dd) tab1 tab2 <- tabular((n=1) + Format(digits=1) * ((x) * (Avg. = mean)) + Format(digits=4) * ((Factor(f1)) * (Pctn. = Percent('col'))) ~ Justify(c) * (f3 + 1), data = dd) Error in justification[j, ] <- rightjustification : number of items to replace is not a multiple of replacement length Best, Lars. [[alternative HTML version deleted]] __ 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. __ 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.
Re: [R] Subsetting vector with preserved order
Hi, Try ?match b[match(d,a)] #[1] "Joe" "Bob" "Dick" A.K. I have three vectors as follows: > a <- c('A','B','C','D','E') > b <- c('Tom','Dick','Harry','Bob','Joe') > d <- c('E','D','B') Subsetting b by using d on a, with b[a %in% d], gives the names in the order they appear in b: > b[a %in% d] > [1] "Dick" "Bob" "Joe" But I'd like them to show in the order in d, as "Joe" "Bob" "Dick". What is the easy way to do this? Thanks. __ 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.
Re: [R] Subsetting vector with preserved order
Hi On 01/02/2014 04:04 PM, arun wrote: Hi, Try ?match b[match(d,a)] #[1] "Joe" "Bob" "Dick" Or use 'a' to put names on 'b': > names(b) <- a > b A B C D E "Tom" "Dick" "Harry" "Bob" "Joe" Then subset by names: > b[d] E D B "Joe" "Bob" "Dick" Cheers, H. A.K. I have three vectors as follows: a <- c('A','B','C','D','E') b <- c('Tom','Dick','Harry','Bob','Joe') d <- c('E','D','B') Subsetting b by using d on a, with b[a %in% d], gives the names in the order they appear in b: b[a %in% d] [1] "Dick" "Bob" "Joe" But I'd like them to show in the order in d, as "Joe" "Bob" "Dick". What is the easy way to do this? Thanks. __ 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. -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpa...@fhcrc.org Phone: (206) 667-5791 Fax:(206) 667-1319 __ 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.
Re: [R] Tracking what R actually executes
On 02-Jan-2014 23:55:28 Duncan Murdoch wrote: > On 14-01-02 6:05 PM, Fisher Dennis wrote: >> R 3.0.2 >> All platforms >> >> Colleagues >> >> This question is probably conceptual rather than technical and I have not >> thought out all of the issues yet. Lets say I have an extensive list of >> functions and some lines of code that call the functions. I would like to >> have a record of all the commands that were actually executed. I realize > that this could be voluminous but it might be necessary. >> For example, the code and function might be: >> >> ### >> INPUT: >> COUNTER <- function(N) >> for (i in 1:N) cat(count, i, \n) >> COUNTER(10) >> >> ### >> OUTPUT: >> cat(count, 1, \n) >> cat(count, 2, \n) >> cat(count, 3, \n) >> cat(count, 4, \n) >> cat(count, 5, \n) >> cat(count, 6, \n) >> cat(count, 7, \n) >> cat(count, 8, \n) >> cat(count, 9, \n) >> cat(count, 10, \n) >> >> # >> If I have formulated the question poorly, please do you best to understand >> the intent. >> >> Dennis > > As far as I know, R doesn't have exactly this built in, but the Rprof() > function gives an approximation. It will interrupt the execution at a > regular time interval (1/50 sec is the default, I think), and record all > functions that are currently active on the execution stack. So tiny > little functions could be missed, but bigger ones probably won't be. > > There are also options to Rprof to give other profiling information, > including more detail on execution position (down to the line number), > and various measures of memory use. > > Duncan Murdoch Also have a look at ?trace which you may be able to use for what you want. Ted. - E-Mail: (Ted Harding) Date: 03-Jan-2014 Time: 00:14:51 This message was sent by XFMail __ 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.
Re: [R] Any R-package geared towards Endorsement Frequencies?
For the likert scale items, please look at the likert function in the HH package. install.package("HH") library(HH) ?likert demo("likert-paper") Rich On Thu, Jan 2, 2014 at 1:10 PM, Lila Lorne wrote: > I am working with a dataset that is observations of mentors or senior > teachers evaluating new or junior teachers in primary classrooms. There are > 27 > items (5-pt Likert) and I would like to know the proportion of > respondents who endorse each response category, including floor and ceiling > effects. I have to report on the viability of dropping items and want to > look at the data from a couple of different perspectives (going to conduct > an EFA next). > > I perused the packages but didn't find any that fit well for my purposes. I > figure EF are routinized somewhere in R, I just need help to find it. > > Best, > Lila > > On Thu, Jan 2, 2014 at 12:02 PM, Ista Zahn wrote: > >> Hi Lila, >> >> You will probably have to be more specific. What exactly do you want >> to do? Have you looked at http://cran.r-project.org/web/views/ ? >> >> Best, >> Ista >> >> On Thu, Jan 2, 2014 at 9:59 AM, Lila Lorne >> wrote: >> > Happy New Year everyone, >> > >> > I need some help figuring out if there is an R package tailored towards >> > endorsement frequencies. Would y'all here know of any such packages that >> > they would recommend I use? >> > >> > Thanks! >> > >> > Lily >> > >> > >> > >> > >> > >> > If it doesn't challenge you, it doesn't change you - Fred DeVito >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > 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. >> > > > > -- > If it doesn't challenge you, it doesn't change you - Fred DeVito > > [[alternative HTML version deleted]] > > __ > 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. __ 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.
[R] A question in rms package
Dear all, Happy new year all of You and with best wishes coming to you in this new year. I have a problem in running a command in rms package. Does any can help me with my problem. I wanna use predab.resample command to compute bias-corrected estimates of a vector of indexes of Predictive accuracy. But I'm confused about choosing fit and measure arguments. Would you please help me? I ran this command: model1=lrm(Cancerous~AGE+PV+PSA,na.action=na.delete,x=TRUE, y=TRUE, data=mdat1) now when I want to use this one: predab.resample<-predab.resample(model, method=c("boot","crossvalidation",".632","randomization"), bw=TRUE, B=50, pr=FALSE, rule="aic", type="residual", sls=.05, aics=0, tol=1e-12, non.slopes.in.x=TRUE) I received this error: Error in predab.resample(model, method = c("boot", "crossvalidation", : argument "fit" is missing, with no default I will be very happy to receive your comments. Many thanks Amir [[alternative HTML version deleted]] __ 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.
Re: [R] A question in rms package
On Jan 2, 2014, at 11:03 AM, Agony wrote: > Dear all, > > Happy new year all of You and with best wishes coming to you in this new year. > > I have a problem in running a command in rms package. > Does any can help me with my problem. > > I wanna use predab.resample command to compute bias-corrected estimates of a > vector of indexes of Predictive accuracy. But I'm confused about choosing fit > and measure arguments. > > Would you please help me? > > I ran this command: > model1=lrm(Cancerous~AGE+PV+PSA,na.action=na.delete,x=TRUE, y=TRUE, > data=mdat1) ___^ > > now when I want to use this one: > > predab.resample<-predab.resample(model, > method=c("boot","crossvalidation",".632","randomization"), _^ Not spelled the same. > bw=TRUE, B=50, pr=FALSE, > rule="aic", type="residual", sls=.05, aics=0, > tol=1e-12, non.slopes.in.x=TRUE) > > > I received this error: > > Error in predab.resample(model, method = c("boot", "crossvalidation", : > argument "fit" is missing, with no default > -- David Winsemius Alameda, CA, USA __ 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.