Displaying 20 results from an estimated 20000 matches similar to: "Summing Select Columns of a Data Frame?"
2011 Dec 19
2
Summing x1 to x6
Suppose I have the following:
x1<-as.vector(rnorm(10))
x2<-as.vector(rnorm(10))
x3<-as.vector(rnorm(10))
x4<-as.vector(rnorm(10))
x5<-as.vector(rnorm(10))
x6<-as.vector(rnorm(10))
x7<-as.vector(rnorm(10))
x8<-as.vector(rnorm(10))
x9<-as.vector(rnorm(10))
x10<-as.vector(rnorm(10))
I would like the mean of x1 to x6 for each vector position. I would do
something else
2013 Apr 18
1
select and do some calculations/manipulations on certain rows based on conditions in R
Hi,
May be this helps (Assuming that there are only '0's and '1's in the dataset)
dat1<-read.table(text="
??????? ID X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15
1?? 5184??? 0??? 0??? 0??? 0??? 0?? 0?? 0??? 0??? 0??? 1???? 0????? 0????? 0????? 0????? 0????? 0
2?? 6884??? 0??? 0??? 1??? 0??? 0?? 1?? 0??? 0??? 0??? 0???? 0????? 0????? 0????? 0????? 0????? 0
3?
2012 Jul 12
3
Add row into a Matrix witout headers from Function
Hi,
Here i have a matrix like this,
OLDMatrix <-
X1 X2 X3
----- ------ ------
22 24 23
25 27 27
10 13 15
the thing is,
im running two function(SUM,COUNT) to get output in another matrix called
NEWMatrix
NEWMatrix <- c("SUM",colSums(OLDMatrix ))
NEWMatrix <- c("COUNT",colSums(!is.na(OLDMatrix
2009 Jul 27
4
dataframe to list conversion
Hi all, I have been experimenting with writing my own matrix column sum
function. I want it to return a list.
csum<-function(m)
{
a = data.frame(m)
s = lapply(a,sum)
return(s)
}
I wish to use the same code up until the return(s) that I have listed above.
The problem is that s, I believe, is a data frame (looks like this:)
$X1
[1] 148
$X2
[1] 156
$X3
[1] 164
$X4
[1] 172
2008 Aug 11
4
how can I do this sum?
Hi,
Suppose I have a vector in real number
(x1, x2, x3, x4, x5, x6)
My question is how I can get
x5*x3*x1 + x6*x4*x2 ?
Thanks a lot.
Dot.
--
View this message in context: http://www.nabble.com/how-can-I-do-this-sum--tp18931693p18931693.html
Sent from the R help mailing list archive at Nabble.com.
2011 Oct 22
1
Does R has a similar way as DATA in SPSS?
Hi there,
In SPSS, small piece of data can be input as following:
DATA LIST LIST /x1 x2 x3 x4 x5 .
BEGIN DATA
5700 12.8 2500 270 25000
1000 10.9 600 10 10000
3400 8.8 1000 10 9000
3800 13.6 1700 140 25000
4000 12.8 1600 140 25000
8200 8.3 2600 60 12000
1200 11.4 400 10 16000
9100 11.5 3300 60 14000
9900 12.5 3400 180 18000
9600 13.7 3600 390 25000
2009 Nov 03
3
re ading tokens
Greetings,
I am not familiar with processing text in R. Can someone tell me how to
read each line of words as separate elements in a list?
FE, I would like to turn:
word1 word2 word3
word2 word4
into a list of length two with three character elements in the first list
and two elements in the second. I know that this should be easy, but I am a
little confused by the text functions.
Thanks in
2012 Sep 12
3
how to create a substraction matrix (subtract a row of every column from the same row in other columns)
Hello
I have data like this
x1 x2 x3 x4 x5
I want to create a matrix similar to a correlation matrix, but with the
difference between the two values, like this
x1 x2 x3 x4 x5
x1 x2-x1 x3-x1 x4-x1 x5-x1
x2 x3-x2 x4-x2 x5-x2
x3 x4-x3 x5-x3
x4 x5-x4
x5
Then I
2003 Aug 13
2
putting NAs at the end
I have a matrix for which each row has 12 elements that represent the xyz coordinates of 4 points.
So each row of M is (x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4). Some points have NA as z values.
I want another matrix to be the same as M but with the coordinates of those points with z=NA placed last.
For ezample if z1=NA then the new matrix row should be (x2,y2,z2,x3,y3,z3,x4,y4,z4,x1,y1,z1)
2007 Jan 30
2
R and S-Plus got the different results of principal component analysis from SAS, why?
Dear Rusers,
I have met a difficult problem on explaining the differences of principal
component analysis(PCA) between R,S-PLUS and SAS/STATA/SPSS, which wasn't
met before.
Althought they have got the same eigenvalues, their coeffiecients were
different.
First, I list my results from R,S-PLUS and SAS/STATA/SPSS, and then show
the original dataset, hoping sb. to try and explain it.
2009 Jan 28
3
initial value in 'vmmin' is not finite
Dear r helpers
I run the following code for nested logit and got a message that
Error in optim(c(0, 0, 0, 0, 0.1, -2, -0.2), fr, hessian = TRUE, method = "BFGS") : initial value in 'vmmin' is not finite
What does this mean? and how can I correct it?
Thank you
June
> yogurt = read.table("yogurtnp.csv", header=F,sep=",")> attach(yogurt)>
2010 Mar 20
2
summated scale
hello,
I am new to R (convert from Stata) and I am wondering if there is an R
command/function for generating a summated scale from, for example, four
separate variables in a data set. In other words, I want to transform the
variables x1, x2, x3, and x4 (which have high inter-item reliability) into
one new summated variable x'. Can't seem to find it in the psy or psych
package ...
2000 Nov 10
3
NLS
Hello,
I try to do a very simple nonlinear regression. The function is
y = (b0 + b1*x1 + b2*x2 + b3*x3) * x4^b4
I think I do everything well, but as I set the starting value of b4 to 0 (it
is the theoretically sane starting value), it converges very quickly, and to
the wrong solution. Wrong in a sense, that 1) we do not expect this and 2) we
do not get this on E-Views, Stata and SAS. I do not
2008 May 07
1
Automatically generating new column names (and columns)
Once again I need to tap into the collective knowledge here.
Let's say I have the following columns and data below
Y X1 X2 X3 X4
I would like to generate additional new columns and column names
(ie the data would be squared - and I'd like the column names to
reflect this) like:
Y X1 X2 X3 X4 X1^2 X2^2 X3^2 X4^2
I believe I can compute the values correctly with the code below, but
I
2012 Mar 13
4
MANOVA and Extra Sums-of-Squares Tests
I would like to conduct an extra sum-of -squares test that compares a full
MANOVA model (with all 1st order interactions) to a reduced model (no
interactions) to determine if I can drop all interactions at the same time.
This is analagous to an extra sum-of-squares F-test in ANOVA, but instead
using MANOVA. Is there a command in R that does this? If not, is there a
command that calculates
2012 Feb 17
5
How to change the order of columns in a data frame?
Dear all,
I have a data frame in which the columns need to be ordered. The first column X is at the right position, but the remaining columns X1-Xn should be ordered like this: X1, X2, X3 etc instead of like below.
> colnames(pos1)
[1] "X" "X1" "X10" "X11" "X12" "X13" "X14" "X15" "X16"
2004 Apr 03
3
Seeking help for outomating regression (over columns) and storing selected output
Hello,
I have spent considerable time trying to figure out that which I am about to describe. This included searching Help, consulting my various R books, and trail and (always) error. I have been assuming I would need to use a loop (looping over columns) but perhaps and apply function would do the trick. I have unsuccessfully tried both.
A scaled down version of my situation is as follows:
2008 Mar 29
1
Tabulating Sparse Contingency Table
I have a sparse contingency table (most cells are 0):
> xtabs(~.,data[,idx:(idx+4)])
, , x3 = 1, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 31
2 0 0 112
3 0 0 94
, , x3 = 2, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 = 3, x4 = 1, x5 = 1
x2
x1 1 2 3
1 0 0 0
2 0 0 0
3 0 0 0
, , x3 = 1, x4
2010 Dec 14
2
How to bind models into a list of models?
Hi R-helpers,
I have a character object called dd that has 32 elements each of which
is a model formula contained within quotation marks. Here's what it
looks like:
> dd
[1] "lm(y ~ 1,data=Cement)" "lm(y ~
X,data=Cement)" "lm(y ~ X1,data=Cement)"
[4] "lm(y ~ X2,data=Cement)" "lm(y ~
2013 May 29
3
bootstrap
Hi,
You might need to check library(boot).? I have never used that before.? So, I can't comment much.? It is better to post on R-help list.? I had seen your postings on Nabble in the past.? Unfortunately those postings were not accepted in R-help.? You have to directly post at ? r-help at r-project.org after registering at:
https://stat.ethz.ch/mailman/listinfo/r-help
?