Re: [Rd] Lemon drops
On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote: I bumped into the following situation: Browse[1] coef deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 Browse[1] coef[,1] [1] 462 Browse[1] coef[,1,drop=F] deg0NA (Intercept)462 where I really wanted neither, but (Intercept) 462 Anyone happen to know a neat way out of the conundrum? I can think of rowSums(coef[,1,drop=F]) or of course val - coef[,1] names(val) - rownames(x)) but the first one is sneaky and the second gets a bit tedious... Peter, How about something like this: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 x[1] (Intercept) 462 str(x[1]) Named num 462 - attr(*, names)= chr (Intercept) Does that work or am I missing something? Marc Schwartz __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Lemon drops
Marc Schwartz [EMAIL PROTECTED] writes: On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote: I bumped into the following situation: Browse[1] coef deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 Browse[1] coef[,1] [1] 462 Browse[1] coef[,1,drop=F] deg0NA (Intercept)462 where I really wanted neither, but (Intercept) 462 Anyone happen to know a neat way out of the conundrum? I can think of rowSums(coef[,1,drop=F]) or of course val - coef[,1] names(val) - rownames(x)) but the first one is sneaky and the second gets a bit tedious... Peter, How about something like this: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 x[1] (Intercept) 462 str(x[1]) Named num 462 - attr(*, names)= chr (Intercept) Does that work or am I missing something? You're missing the context. What I really need is something that will extract a column of a matrix as a vector in the usual way, but will not get confused if there is only one row. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Lemon drops
On Tue, 2005-03-15 at 18:26 +0100, Peter Dalgaard wrote: Marc Schwartz [EMAIL PROTECTED] writes: On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote: I bumped into the following situation: Browse[1] coef deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 Browse[1] coef[,1] [1] 462 Browse[1] coef[,1,drop=F] deg0NA (Intercept)462 where I really wanted neither, but (Intercept) 462 Anyone happen to know a neat way out of the conundrum? I can think of rowSums(coef[,1,drop=F]) or of course val - coef[,1] names(val) - rownames(x)) but the first one is sneaky and the second gets a bit tedious... Peter, How about something like this: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 x[1] (Intercept) 462 str(x[1]) Named num 462 - attr(*, names)= chr (Intercept) Does that work or am I missing something? You're missing the context. What I really need is something that will extract a column of a matrix as a vector in the usual way, but will not get confused if there is only one row. OK. scratching head. Well, thinking that there was an approach using t(), it works, but retains a 2 dim structure which is not what you want. It also retains the colname from the original structure as the rowname for the new construct. I don't have another idea at this point for you, but I'll keep thinking... :-) Marc __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Lemon drops
On 15 Mar 2005 18:26:46 +0100 Peter Dalgaard wrote: Marc Schwartz [EMAIL PROTECTED] writes: On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote: I bumped into the following situation: Browse[1] coef deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 Browse[1] coef[,1] [1] 462 Browse[1] coef[,1,drop=F] deg0NA (Intercept)462 where I really wanted neither, but (Intercept) 462 Anyone happen to know a neat way out of the conundrum? I can think of rowSums(coef[,1,drop=F]) or of course val - coef[,1] names(val) - rownames(x)) but the first one is sneaky and the second gets a bit tedious... Peter, How about something like this: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 x[1] (Intercept) 462 str(x[1]) Named num 462 - attr(*, names)= chr (Intercept) Does that work or am I missing something? You're missing the context. What I really need is something that will extract a column of a matrix as a vector in the usual way, but will not get confused if there is only one row. Maybe: coef[,1,drop=FALSE][1:nrow(coef)] ? Z -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Lemon drops
On Tue, 2005-03-15 at 20:05 +0100, Achim Zeileis wrote: On 15 Mar 2005 18:26:46 +0100 Peter Dalgaard wrote: Marc Schwartz [EMAIL PROTECTED] writes: On Tue, 2005-03-15 at 18:05 +0100, Peter Dalgaard wrote: I bumped into the following situation: Browse[1] coef deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 Browse[1] coef[,1] [1] 462 Browse[1] coef[,1,drop=F] deg0NA (Intercept)462 where I really wanted neither, but (Intercept) 462 Anyone happen to know a neat way out of the conundrum? I can think of rowSums(coef[,1,drop=F]) or of course val - coef[,1] names(val) - rownames(x)) but the first one is sneaky and the second gets a bit tedious... Peter, How about something like this: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 x[1] (Intercept) 462 str(x[1]) Named num 462 - attr(*, names)= chr (Intercept) Does that work or am I missing something? You're missing the context. What I really need is something that will extract a column of a matrix as a vector in the usual way, but will not get confused if there is only one row. Maybe: coef[,1,drop=FALSE][1:nrow(coef)] ? Z Hinteresting. At the risk of this degenerating into an obfuscated R contest, Achim's post just gave me an idea to build on my original thought: # With one row: x deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 apply(t(x)[1, , drop = FALSE], 2, FUN = [) (Intercept) 462 # Now with two rows: x2 deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP (Intercept)462510528492660762 IV1 1 2 3 4 5 6 apply(t(x2)[1, , drop = FALSE], 2, FUN = [) (Intercept) IV1 462 1 Marc __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] Lemon drops
Peter Dalgaard p.dalgaard at biostat.ku.dk writes: : : I bumped into the following situation: : : Browse[1] coef : deg0NA deg4NA deg8NA deg0NP deg4NP deg8NP : (Intercept)462510528492660762 : Browse[1] coef[,1] : [1] 462 : Browse[1] coef[,1,drop=F] : deg0NA : (Intercept)462 : : where I really wanted neither, but : : (Intercept) : 462 : : Anyone happen to know a neat way out of the conundrum? : : I can think of : : rowSums(coef[,1,drop=F]) : : or of course : : val - coef[,1] : names(val) - rownames(x)) : : but the first one is sneaky and the second gets a bit tedious... : If by tedious you mean its not a single expression then the basic idea of your solution #2 can be preserved while doing it in a single expression like this: structure(coef[,1], .Names = rownames(x)) __ R-devel@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-devel