Displaying 20 results from an estimated 2521 matches for "colnames".
2009 Mar 27
2
adding matrices with common column names
folks,
if i have three matrices, a, b, cc with some colnames in common, and i
want to create a matrix which consists of the common columns added up,
and the other columns tacked on, what's a good way to do it? i've got
the following roundabout code for two matrices, but if the number of
matrices increases, then i'm a bit stymied.
> a <- m...
2013 Mar 21
4
easy way of paste
Hello,
Is there a better way to use paste such as:
a = paste(colnames(list.indep)[1],colnames(list.indep)[2],colnames(list.indep)[3],colnames(list.indep)[4],colnames(list.indep)[5],sep="+")
> a
[1] "aa+dummy1+dummy2+bb+cc"
I tried
a = paste(colnames(list.indep)[1:5],sep="+")
> a
[1] "aa" "dummy1"...
2007 Nov 07
2
Trouble in creating a list
I want to create a list based on the information from a data.frame,
Model. So I tried the following:
MyList <- list(colnames(Model)[2] = levels(Model$(colnames(Model)[2])))
but it failed with an error:
Error: unexpected '=' in "list(colnames(Model)[2] ="
I have the following problems with this command line:
(1) I wanted to use colnames(Model)[2] as a tag for the list:
> colnames(Model)[2]
[1] &...
2005 Jul 20
3
Prefix for colnames
Hi,
I would like to add a prefix to colnames in a matrix but I can't get the prefix
option in colnames to work. What am I doing wrong?
> X<-matrix(NA,3,4)
> colnames(X)<-c("test","test","test","test")
> colnames(X)<-colnames(X,prefix="PREFIX.")
> X
test test test...
2017 Jan 19
2
Error en loop anidado con data.table
...f10,rankf12))
datos<-data.table((datos),key="anireg_cod")
datos[order(anireg_cod,decreasing=FALSE),]
anio<-sort((unique(datos$anireg_cod)))
tiempo<-as.character(c("t_8a","t_10a","t_12a"))
mat<-matrix(c(100,50,NA,200,150,250,200,150,250),3,3)
colnames(mat)<-tiempo
rownames(mat)<-seq(1:length(sort(unique(datos$anireg_cod))))
anio<-sort((unique(datos$anireg_cod)))
rank<-as.character(c("rankf8","rankf10","rankf12"))
for (k in 1:nrow(datos)){
#recorre variable anio
for (i in anio){
for(j in ti...
2011 Sep 16
2
Referring to an object by a variable containing its name: 6 failures
Dear Folks--
I'm trying to make a function that takes the columns I select from a data
frame and then uses a for loop to print some information about each one,
starting with the column name. I succeed in returning the column name, but
nothing else I have tried using the variable colName, containing the name of
the column, to refer to the column itself has worked.
Below I show my
2007 Nov 26
2
colnames slow (PR#10470)
Full_Name: Tomas Larsson
Version: 2.6.0
OS: Windows XP
Submission from: (NULL) (198.208.251.24)
This is not a bug, it is a performance issue but I think it should have an easy
fix.
I have a large matrix (about 2,000,000 by 20), when I type colnames(x) it takes
a long time to get the result. However, if I select just the first couple of
rows of the matrix I don't have to wait for the result. See below for example.
> system.time(colnames(x))
user system elapsed
9.98 0.00 10.00
> system.time(colnames(x[1:2,]))
user...
2012 Feb 14
2
save objects of own function to workspace
Dear R-helpers,
I created an own function which looks like this
s_elternmz <- function(Var="balt")
{
Dg_a<-mz[,c("asbhh","apkz",Var)]
colnames(Dg_a)[colnames(Dg_a)=="apkz"]<-"bpkzm"
colnames(Dg_a)[colnames(Dg_a)==Var]<-paste(Var,"_m",sep="")
mz_int<-merge(mz,Dg_a,by=c("asbhh","bpkzm"),all.x=T)
colnames(Dg_a)[colnames(Dg_a)=="bpkzm"]<-"bpkzv"...
2020 Apr 25
2
problemas al cambiar el nombre de una variable
Buenos días, al final de un loop añado 3 variables que acabo de crear, a
una df, y les pongo un nombre.
Las variables son Max, Min y Mean.
Las añado a BData7085:
BData7085$Max<-Max
BData7085$Min<-Min
BData7085$Meann<-Mean (hasta aquí bien)
Para ponerles su nombre final:
colnames(BData7085)[ncol-2]<-paste(colnames(Data)[j],"max",sep = "")
colnames(BData7085)[ncol-1]<-paste(colnames(Data)[j],"min",sep = "")
colnames(BData7085)[ncol]<-paste(colnames(Data)[j],"mean",sep = "")
para las dos primeras me da:...
2013 Sep 05
2
binary symmetric matrix combination
...e5 l15
y1 0 1 1 1 1 1 1 1 1 1
g24 1 0 0 0 0 0 0 0 0 0
c1 1 0 0 1 1 0 0 0 0 0
c2 1 0 1 0 1 0 0 0 0 0
l17 1 0 1 1 0 0 0 0 0 0
h4 1 0 0 0 0 0 1 1 0 0
s2 1 0 0 0 0 1 0 1 0 0
s30 1 0 0 0 0 1 1 0 0 0
e5 1 0 0 0 0 0 0 0 0 1
l15 1 0 0 0 0 0 0 0 1 0",sep="",header=TRUE))
names1<-unique(c(colnames(m1),colnames(m2),colnames(m3),colnames(m4)))
Out2<-matrix(0,length(names1),length(names1),dimnames=list(names1,names1))
vec1<- paste0(colnames(m1)[col(m1)],rownames(m1)[row(m1)])
vecOut<- paste0(colnames(Out2)[col(Out2)],rownames(Out2)[row(Out2)])
Out2[match(vec1,vecOut)]<- m1
vec2<-...
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" "X17" "X18" "X19" "X2" "X20" "X3" "X4" "X5" "X6"...
2010 Jul 09
2
select columns from vector of column names
Hi
I want to extract columns from a data frame using a vector with the desired
column names.
This short example uses the select argument in the subset function to
accomplish what I am trying to do. Is there a better solution?
#names of desired columns
colnames <- c("col1","col3")
#my data
data <- data.frame("col1"=c(1,2,3),"col2"=c("A","B","C"),"col3"=c(4,5,6))
fun <- function(colname,dframe){
nframe <- subset(dframe,select=colname)
vec <- nframe[,1]...
2004 Sep 17
1
Confused about specifying plot colors as RGB values
Based on reading 'rgb' documentation, I would have thought
the following would have produced identical results. Can
someone explain how to make this happen? I need to be able
to specify an array of rgb values for the 'col' parameter.
colnames.col <- c("black", "red", "blue", "green")
colnames.rgb <- apply(as.matrix(colnames.col), 1, col2rgb)
dimnames(colnames.rgb)[[2]] <- colnames.col
baseline <- 1:32
offset2 <- 2*baseline
offset3 <- 3*baseline
offset4 <- 4*baseline
offsets &...
2004 Dec 21
1
about colnames
Try
colnames(df)[4:6] <- c("x","y","z")
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of
xmeng at capitalbio.com
Sent: 21 December 2004 09:45
To: r-help at stat.math.ethz.ch
Subject: [R] about colname...
2008 May 06
3
a R_PV problem
Dear all,
When using gdb to debug my C code, I use R_PV to show the content of
SEXP variables:
SEXP sexp; // it is a data.frame
SEXP colNames = getAttrib(sexp, R_NameSymbol);
A strange thing is that after halting the program:
(gdb) p R_PV(colNames)
does not show the content of colNames. I am positive my code is right
because if I insert "PrintValue(colNames);" in the c code, it will
print the right value. My debug result s...
2017 Oct 23
2
A list of data frames and a list of colnames.
I have a list of file names, and a list of data frames contained in those files.
mynames <- list.files()
mydata <- lapply(mynames, read.delim)
Every file contains two columns.
> colnames(mydata[[1]])
[1] "Name" "NumReads"
> colnames(mydata[[2]])
[1] "Name" "NumReads"
I can set the colnames easily enough with a for loop.
for (i in seq_along(mynames)) {
colnames(mydata[[i]])[2] <- mynames[i]
}
Is there a nicer way to do thi...
2006 May 17
0
variable colnames
Hy all,
I apologize i've used rownames instead of colnames in my first exemple. (that's why i changed the mail object) I was on mars when i wrote my question...
Every answer where correct ... but, because i've made a wrong question, people wern't able to understand...
So finally i'm speaking about colnames :
Let's be more precise:
I...
2006 Mar 21
1
rownames, colnames, and date and time
I noticed something surprising (in R 2.2.1 on WinXP)
According to the documentation, rownames and colnames are character vectors.
Assigning a vector of class POSIXct or POSIXlt as rownames or colnames
therefore is not strictly according to the rules.
In some cases, R performs a reasonable typecast, but in some other cases
where the same typecast also would be possible, it does not.
Assigning a vector o...
2006 Mar 21
1
rownames, colnames, and date and time
I noticed something surprising (in R 2.2.1 on WinXP)
According to the documentation, rownames and colnames are character vectors.
Assigning a vector of class POSIXct or POSIXlt as rownames or colnames
therefore is not strictly according to the rules.
In some cases, R performs a reasonable typecast, but in some other cases
where the same typecast also would be possible, it does not.
Assigning a vector o...
2011 Jun 20
6
for loop and linear models
Hi,
I have two datasets, x and y. Simplified x and y denote:
X
Y
A B C A B C . . . . . . . . . . . . . . . . . .
I want to implement all possible models such as lm(X$A~Y$A), lm(X$B~Y$B),
lm(X$C~Y$C)... I have tried the following:
fun<- function(x,y){
for(i in 1:length(colnames(x))){
for(j in 1:length(colnames(y))){
if(colnames(x)[i]==colnames(y)[j]){
models=list(lm(ts(x[i])~ts(y[j])))
}
else{}
}
}
return(models)
}
The problem is that this returns only one of the th...