d*********k 发帖数: 1239 | 1 用了dataframe啊,然后 dim() 给我的是3*4矩阵,我可以改colnames和rownames,这
个没有问题
但是怎么给最开始的一列(暂且叫0列,也就是rownames)加个名字呢?就是rownames
()表示的是年份1990,1991,1992,我想在最左上角加个名字
不知道我解释清楚我想干嘛了没有~~ 谢谢啦 |
|
d*********k 发帖数: 1239 | 2 A B C D
1990 1 2 3 4
1991 5 6 7 8
1992 9 0 1 2
我想把上面这个3*4的矩阵的时间也就是rownames起个名字,然后变成如下的矩阵:
Year A B C D
1990 1 2 3 4
1991 5 6 7 8
1992 9 0 1 2
这个咋弄啊?google了半天都没有找到解决办法~ 有谁知道怎么弄么?
谢谢了啊 |
|
l*********s 发帖数: 5409 | 3 No such thing, aif you worry that row names are confusing, change them
to 1990yr etc. for clarity.
rownames |
|
t****a 发帖数: 1212 | 4 it is possible.
assuming that your matrix is m
them you can define names(dimnames(m)) = c(rownames.title, colnames.title) |
|
t****a 发帖数: 1212 | 5 it is possible.
assuming that your matrix is m
them you can define names(dimnames(m)) = c(rownames.title, colnames.title) |
|
l*******d 发帖数: 101 | 6 跟DaShagen写的大同小异。把找出来的值加进去。
> n = 4
> threshhold = 5
> X = matrix (1:16, byrow=TRUE, ncol=n, dimnames=list(1:4, c("A", "B", "C",
"D")))
> X
A B C D
1 1 2 3 4
2 5 6 7 8
3 9 10 11 12
4 13 14 15 16
> ind = which (X>threshhold, arr.ind=TRUE)
> findNames = data.frame (ind, rowName=rownames(X)[ind[,1]], colName=
colnames(X)[ind[,2]], value=as.vector(X)[(ind[,2]-1)*n+ind[,1]], row.names=
NULL)
> findNames
row col rowName colName value
1 3 1 3 A 9
2 4 1 4 |
|
q**j 发帖数: 10612 | 7 多谢帮助!
1. 如果一个data frame 有 (key1, key2, var1),另外一个有(key1, key2, var2)。
我希望找出在第一个data frame里面,但是不在第二个里面的所有行。请问是否必须要
像SAS那样建立in1, in2然后经过merge()以后挑选?有没有简单的办法?(var1 var2
可能是missing)。
2.
> data
x y z
1 apple 1996 1
2 orange 1997 2
3 orange 1996 3
4 apple 1998 4
5 apple 1997 5
> new
[,1] [,2] [,3]
[1,] NA NA NA
[2,] NA NA NA
> rownames(new) = unique(x)
> colnames(new) = unique(y)
> new
1996 1997 1998
apple NA NA NA
orange NA NA NA
> Row.Index = match(data$x,rownames(new)) |
|
o******6 发帖数: 538 | 8 ☆─────────────────────────────────────☆
qqzj (小车车) 于 (Thu Feb 26 15:48:04 2009) 提到:
好奇心强,同一个工作用R和python各搞了一次。数据文件是709 by 88的.csv文件。如
下是R code: (code 写的不好,希望拍砖帮我改进。)
************************************************************************
Data = read.csv("D:/VP_BAP.csv")
NoRow = dim(Data)[1]
NoCol = dim(Data)[2]
RowName = Data[,1]
ColName = colnames(Data)
Output = c("","")
for (i in 1:NoRow){
for (j in 1:NoCol){
if (Data[i,j]==c("N")){
Temp = c(as.character(RowName[i] |
|
a***r 发帖数: 420 | 9 有个n*n的matrix(result),有col和row name,我想保留这个matrix中大于5的值,
并且保留这些值对应的colname和rowname,因为这个是这些值的来源信息。
不知道有没有专门的语句,发挥主观能动性写了一个:
threshold<-matrix(,ncol=4,nrow=n*n)
for (i in 1:(n-1)){
for (j in (i+1):n) {
if (result[i,j]>5)
threshold[((i-1)*n+j),1] <-rownames(result)[i]
threshold[((i-1)*n+j),2] <-colnames(result)[j]
threshold[((i-1)*n+j),3] <-as.numeric(result[i,j])
}
}
threshold <- threshold[complete.cases(threshold),]
总觉得有点笨哪,有没有语句直接能实现的呢?
谢谢大家! |
|
q**j 发帖数: 10612 | 10 好像是rownames和column names不一样造成的。这个也太不合理了吧。
> colnames(S)=1:12
> rownames(S)=1:12
> all.equal(S, t(S))
[1] TRUE
请问有没有简单的办法让R不这么变态。明明是个矩阵么。
V
-0
-0
-0
-0 |
|
b******o 发帖数: 545 | 11 Error in .Call("WriteXls", x, file, colNames, sheet, from - 1, rowNames, :
Incorrect number of arguments (7), expecting 6 for WriteXls
================================================================
what's that means? |
|
R****n 发帖数: 708 | 12 my simple R code. Try to read the basic R, and you should be able to get it
in a few weeks.
setwd("C:/Users/meng09/Downloads/BRCA/BCGSC__IlluminaHiSeq_miRNASeq/Level_3")
lst<-list.files()
exprtable<-c()
Nam<-c()
for (f in lst) {
temp<-read.delim(f)
Nam<-c(Nam,as.character(temp[1,"barcode"]))
exprtable<-cbind(exprtable,temp[,"reads_per_million_miRNA_mapped"])
}
exprtable[1:5,1:5]
exprs<-as.data.frame(exprtable)
samp<-Nam
probe<-as.character(temp[,"miRNA_ID"])
names(exprs)<-samp
rownames(exp... 阅读全帖 |
|
G***G 发帖数: 16778 | 13 a data.frame in R like
column1 column2
rowname1 0.1 0.3
rowname2 0.4 0.2
rowname3 0.5 0.1
How can I extract the second column with the rowname remained?
column2
rowname1 0.3
rowname2 0.2
rowname3 0.1
thanks. |
|
i***l 发帖数: 1656 | 14 不难啊
重建一个新的
data.frame2(data.frame$column2)
如果你想把那些RowName包括进来,可以加一个新的列 命名为“ID”就好了。 |
|
G**********8 发帖数: 38 | 15 I create a uipanel in a figure, after some calculations, a uitable is
plotted in this panel with some data.
And I want to visualize the data in another axes plot (same figure). Do you
know how I can pass the data from uitable to the axes. I am kind of new to
GUI design. Thanks a lot for your help.
Example: handles.data_table is the tag for the uipanel.
columnname = {'Algorithm', 'Classification Rate'};
columnformat = {'char', 'numeric'};
columneditable = [false false];
t = uitable('Units','no... 阅读全帖 |
|
f**********e 发帖数: 48 | 16 #R code, simple implementation, your data frame is df
cl<-colnames(df)
rw<-rownames(df)
cl_len<-length(cl)
rw_len<-length(rw)
new_rname<-character(cl_len*rw_len)
new_data<-numeric(cl_len*rw_len)
index<-0
for (i in 1:cl_len){
for (j in 1:rw_len){
index<-index+1
new_rname[index]<-paste(rw[j],cl[i])
new_data[index]<-df[i,j]
}
}
data.frame(new_rname,new_data)
|
|
s*****n 发帖数: 2174 | 17 给你写个example, 抛砖引玉吧
假设你的矩阵叫做 A, 目标data frame叫做 result.
result <- data.frame(
RowName = rep(dimnames(A)[[1]], dim(A)[2]),
ColName = rep(dimnames(A)[[2]], each = dim(A)[1]),
Value = as.vector(A))
result <- result[result$Value > 5, ]
在R里面, 要尽量避免循环啦. |
|
p***r 发帖数: 920 | 18 data<-data.frame(matrix(101:106,2,3))
> data
X1 X2 X3
1 101 103 105
2 102 104 106
> newdata<-
data.frame(id=rep(rownames(data),dim(data)[2]),varname=rep(colnames(data
),dim(data)[1]),value=c(t(as.matrix(data))))
> newdata
id varname value
1 1 X1 101
2 2 X2 103
3 1 X3 105
4 2 X1 102
5 1 X2 104
6 2 X3 106 |
|
d*******1 发帖数: 854 | 19 does "do it one by one" requir explicit loop? I think my first solution is "
do it one by one" because i take one gene value at a time and repeat this 50
,000 times as follows:
allCorrData <- as.data.frame(
matrix(ncol=dim(geneData)[1]))
names(allCorrData) = rownames( geneData )
for( i in 1:dim(geneData)[1] ){
newcor <- cor.test( as.matrix( geneData["1557027_at",-c(1)]),
as.matrix( geneData[i,-c(1)]), method="pearson" );
allCorrData[i] = newcor$p.value;
}
i do need p value for the co |
|
f******9 发帖数: 267 | 20 How to find the numbers which are more than 0.5 in a matrix (and with their
rownames and colnames)?
for example, in this matrix:
[,1] [,2] [,3] [,4] [,5]
[1,] 1.0000000000 0.0320075758 0.1183712121 0.0293040293 0.0083333333
[2,] 0.0320075758 1.0000000000 0.0571428571 0.1668650794 0.0004662005
[3,] 0.1183712121 0.0571428571 1.0000000000 0.0053418803 0.0028846154
[4,] 0.0293040293 0.1668650794 0.0053418803 1.0000000000 0.0426767677
[5,] 0.008333 |
|
z**********i 发帖数: 88 | 21 Using SAS to subset data, I can get N=48, but using R, I can not, I don't
know anything about. Would anybody check my R code and see where is the
problem? Below is the SAS code and R code. Thanks.
data x;
set ALL_12222010;
where tau>93 & abeta142<192 & PTAU181P>23;run; **n=48;
#R code;
sizing <- function(variable.name,dx.group){
cut.sample <- function(variable.name,dx.group){
attach(variable.name)
variable.name$enrich=as.numeric(tau>93 & abeta142<192 & PTAU181P>23);
... 阅读全帖 |
|
S********a 发帖数: 359 | 22 我怎么找出我的perl是多少呢,我目前的理解是不止一个方法读取XLS,哪个最方便使
用呢?
或者我用
library(xlsReadWrite)
mydata<-read.xls("c:\L\NJ\Study\copy.xls", colNames=TRUE)
出下面错误信息
Error in .Call("ReadXls", file, colNames, sheet, type, from, rowNames, :
Incorrect number of arguments (11), expecting 10 for ReadXls
怎么改呢? |
|
J****n 发帖数: 54 | 23 > aaa <- read.xls(rfile)
Error in .Call("ReadXls", file, colNames, sheet, type, from, rowNames, :
Incorrect number of arguments (11), expecting 10 for ReadXls
大家遇到过这个错么?怎么改?(Windows OS)
Thanks. |
|
b*****n 发帖数: 685 | 24 colnames()=NULL
rownames()=NULL |
|
t****a 发帖数: 1212 | 25 You can use fisher exactly test to tell if the overlapping is random. Before
doing this you need to now that the size of the background (the DaShagen's
questions: How many genes are there?). In the following code I just assumed
the background size is 20000, both A and B are sampled from the background.
# R code here.
bg <- 20000; a <- 3000; b <- 4000; ab <- 500
your.data <- matrix(c(ab, a-ab, b-ab, bg-a-b+ab), 2, 2)
colnames(your.data) <- rownames(your.data) <- c('In Group', 'Not In Group')
name... 阅读全帖 |
|
|
c*****a 发帖数: 808 | 27 这个我就不会了。
如果一是matrix什么的,你可以加上一个新的时间column啊。as.matrix和 as.data.
frame之类乱convert下,左边会变成obs 1,2,3,4... |
|
d*********k 发帖数: 1239 | 28 这也是我能想到得办法啦,不行就这么弄吧
谢谢了啊啊 |
|
|
|
c**i 发帖数: 234 | 31 create a vector, cbind(vector, matrix)? |
|
W***Y 发帖数: 27 | 32 我想把一个6*4 的matrix 里的每一行的四个数,重新组成一个2*2 matrix , (就是
第一和第二个数作为新的2*2 matrix 里的第一行,第3和4 个数,做第二行,然后,把
每个2*2 matrix 用fisher.test, 算出P-value, 再把所有P-value 按大小排序。
我自己的 code 如下,但是,只计算最后一行的。 请教,问题在哪里?帮我修改一下
吧。
多谢了
rm(list=ls())
fly <- read.table( "fly-7.txt",header=T)
names(fly)
rownames(fly) <- paste( "Gene", 1:nrow(fly), sep="_" )
fly <- as.matrix( fly)
n=nrow(fly)
res=matrix(0,nrow=n, ncol=1,byrow="T")
i<-c(1:n)
for(i in 1:n){
x_i<-as.numeric(fly[i,])
(x_i_12=c(x_i[1],x_i[2]))
(y_i_34=c(x_i[3],x_i[4]))
x... 阅读全帖 |
|
X***n 发帖数: 366 | 33 colnames(matrix) <- c("some", "thing","else")
rownames(matrix) <- c("row1", "row2", "row3) |
|
p****r 发帖数: 46 | 34 # create matrix from applist, then transpose it
# so the matrix is N rows * 10 columns
app <- t(data.frame(applist))
# Same for scorelist
score<- t(data.frame(scorelist))
# generate column sequence (1,11,2,12...10,20) so as to reorder them after
cbind
cols <- rep(1:10,each=2)+rep(c(0,10),10)
# or you can do cols <- unlist(sapply(1:10,function(x) list(x,x+10)))
data <- cbind(app,score)
# reorder columns
data <- data[,cols]
# generate col_names: "applist1", "scorelist1", "applist2","scorelist2"...... 阅读全帖 |
|