You could use transform() instead of [[<- to add columns to your data.frame
so the new columns get transformed they way they do when given to the
data.frame function itself. E.g.,
> dd <- data.frame(X=1:5, Y=11:15)
> str(transform(dd, Z=matrix(X+Y,ncol=1,dimnames=list(NULL, "NewZ"
'data.frame
> On Apr 23, 2016, at 8:59 AM, thomas mann wrote:
>
> I am attempting to add a calculated column to a data frame. Basically,
> adding a column called "newcol2" which are the stock closing prices from 1
> day to the next.
>
> The one little hang up is the name of the column. There seems to be
or
d = data.frame(Col1=c(1,2,3),Col2=c(2,3,4),Col3=c(3,4,5))
names(d)
names(d)[1] = "NewName1"
names(d)
HTH
Pete
--
View this message in context:
http://r.789695.n4.nabble.com/data-frame-column-name-change-tp3220684p3221214.html
Sent from the R help mailing list archive at Nabble.com.
Hi eric,
Try
colnames(x)
colnames(x)[1] <- 'newname'
colnames(x)
HTH,
Jorge
On Sun, Jan 16, 2011 at 11:28 PM, eric <> wrote:
>
> How do I change the name of one column in a data frame ? Suppose I have a
> data frame x with 5 columns. If the names were date, col1, col2, col3, col4
> and I want
On Mar 5, 2010, at 8:26 AM, ManInMoon wrote:
I have a big data frame and I have extracted a bit by doing:
y<-d[1:10,6]
y
[1] Headings 0-49 -98 -49 -41 -120
-155
-204 -169
92329 Levels: -0 -1 -10 -100 -1000 -1 -10001 -10002 -10003
-10004 -10005
-10
On Sep 22, 2009, at 5:07 PM, bamsel wrote:
Any help is very much appreciated. The following is a toy example:
#1. Create a data frame with two named columns (x,y):
DF <- data.frame(cbind(x=1:5, y=6:10))
DF
x y
1 1 6
2 2 7
3 3 8
4 4 9
5 5 10
#2. Define a function to compute the sum o
First - you need to pass the data frame into the function.
testing <- function (d, colname) {
return (d[[colname]])
}
d <- data.frame(cbind(x=1, y=1:10))
print (testing(d, 'x'))
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of eric lee
Sent: Friday, S
7 matches
Mail list logo