Hướng dẫn convert excel to matrix in r - chuyển đổi excel thành ma trận trong r

David L Carlson Dcarlson tại Tamu.edu Mon tháng 7 23 17:47:50 CEST 2012 DCARLSON tại Tamu.edu Mon 23 17:47:50 CEST 2012
DCARLSON tại Tamu.edu Mon 23 17:47:50 CEST 2012
  • Thông báo trước: [R] Nhập tệp Excel - Định dạng Ma trận
  • Thông báo tiếp theo: [R] Kích thước bộ nhớ
  • Tin nhắn được sắp xếp bởi: [Ngày] [Chủ đề] [Chủ đề] [Tác giả] [ date ] [ thread ] [ subject ] [ author ]

Use read.table() with the row.names= argument set to the column number that
represents the row.names (presumably 1) and then convert the data.frame to a
matrix:

A <- read.table(file="fname.csv", row.names=1)
B <- as.matrix(A)

If you are using Windows, you can open Excel, copy the data, Copy and then
change "fname.csv" to "clipboard-128" and R will read the data from the
Windows clipboard.

----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352




> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of arun
> Sent: Saturday, July 21, 2012 8:16 PM
> To: biostat1
> Cc: R help
> Subject: Re: [R] Excel file Import - to Matrix format
> 
> Hello,
> 
> Try this:
> 
> You can use the read.table with sep="," if it is comma separated to
> read the file.
> 
> test1<-read.table(text="
> 0.141  0.242  0.342
> 0.224  0.342  0.334
> 0.652  0.682  0.182
> ",sep="",header=FALSE)
>  #Read data
> test1
>  #   V1    V2    V3
> #1 0.141 0.242 0.342
> #2 0.224 0.342 0.334
> #3 0.652 0.682 0.182
> 
> 
> #Convert to matrix as it is that you wanted
> test2<-as.matrix(test1)
> colnames(test2)<-NULL
> genelist<-c("Fkh2","Swi5","Sic1")
> rownames(test2)<-genelist
> test2
> #      [,1]  [,2]  [,3]
> #Fkh2 0.141 0.242 0.342
> #Swi5 0.224 0.342 0.334
> #Sic1 0.652 0.682 0.182
> 
> #2nd case: As in your example,
> test1<-read.table(text="
> IMAGE:152 0.141  0.242  0.342
> IMAGE:262 0.224  0.342  0.334
> IMAGE:342 0.652  0.682  0.182
> ",sep="",header=FALSE)
> 
> test2<-as.matrix(test1[-1])
> colnames(test2)<-NULL
> genelist<-c("Fkh2","Swi5","Sic1")
> rownames(test2)<-genelist
> test2
> #      [,1]  [,2]  [,3]
> #Fkh2 0.141 0.242 0.342
> #Swi5 0.224 0.342 0.334
> #Sic1 0.652 0.682 0.182
> 
> A.K.
> 
> 
> ----- Original Message -----
> From: biostat1 
> To: r-help at r-project.org
> Cc:
> Sent: Saturday, July 21, 2012 7:29 PM
> Subject: [R] Excel file Import - to Matrix format
> 
> Hi,
> 
> New to R. Need a bit of help. Thanks
> 
> I am trying to import data from Excel file. The package I am trying to
> use
> requires data in Matrix format.
> 
> Excel -> R Matrix with the constraint that the very first column in
> Excel
> file should became the names for rows of the matrix.
> 
> Example. Data has 1000 rows and 11 columns.
> 1st column is the names of Genes
> 10 coulmns of numerical data.
> 
> I need to read this into R.
> it should be a 1000 (row) X 10 Column (Matrix)
> 1st column of Excel file becomes name of the rows.
> 
> I am experimenting with reading as data frame (as I am unable to
> find any info on reading into matrix)  split the data frame, etc.
> 
> Thanks truly appreciate your help.
> 
> What I need: http://r.789695.n4.nabble.com/file/n4637332/thisWorks2.png
> 
> http://r.789695.n4.nabble.com/file/n4637332/doesNotWork1.png
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Excel-file-
> Import-to-Matrix-format-tp4637332.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


  • Thông báo trước: [R] Nhập tệp Excel - Định dạng Ma trận
  • Thông báo tiếp theo: [R] Kích thước bộ nhớ
  • Tin nhắn được sắp xếp bởi: [Ngày] [Chủ đề] [Chủ đề] [Tác giả] [ date ] [ thread ] [ subject ] [ author ]

Thêm thông tin về danh sách gửi thư R-Help

Tôi có một tệp Excel với dữ liệu sau

Hướng dẫn convert excel to matrix in r - chuyển đổi excel thành ma trận trong r

Tôi muốn tạo một bảng ma trận ra khỏi vấn đề này, một cách nhanh chóng để thực hiện nó là gõ thủ công mã sau

table <- matrix(c(292, 289, 299, 333, 253, 260, 260, 284, 262, 326, 120, 108, 120, 116, 106, 102, 114, 127, 130, 155), ncol = 2)

Tuy nhiên, nếu tôi có dữ liệu với 100 mục nhập, có cách nào nhanh hơn để thực hiện không?

Cảm ơn bạn!

Làm cách nào để tạo một ma trận từ dữ liệu trong excel?

Làm thế nào để tạo một ma trận trong Excel..
Hiển thị cửa sổ "Smartart". Để hiển thị cửa sổ "SmartArt", nhấp vào tab "Chèn" trên ruy băng lệnh. ....
Chọn ma trận của bạn. ....
Nhập dữ liệu của bạn vào ma trận. ....
Thiết kế ma trận của bạn. ....
Bao gồm các chi tiết bổ sung. ....
Lưu bảng tính của bạn ..

Làm cách nào để chuyển đổi bảng Excel thành R?

Các bước để nhập tệp Excel bằng tùy chọn tập dữ liệu từ cửa sổ môi trường của RStudio:.
Bước 2: Chọn tùy chọn của từ Excel, theo tùy chọn Nhập dữ liệu. ....
Bước 3: Chọn tùy chọn Duyệt và chọn tệp Excel để được nhập. ....
Bước 4: Chọn tùy chọn Nhập và tệp Excel được nhập thành công ..

Làm cách nào để chuyển đổi excel thành vector trong r?

Các cách tiếp cận để chuyển đổi cột Excel thành vector trong ngôn ngữ R được liệt kê như sau: Sử dụng $ -Operator với tên cột. Sử dụng phương pháp của cột tập hợp. Sử dụng chức năng kéo từ thư viện DPPLY từ ngôn ngữ R.Using $-Operator with the column name. Using the method of Subsetting column. Using pull function from dplyr library from the R language.

Làm cách nào để tạo ma trận dữ liệu trong r?

Làm thế nào để tạo một ma trận trong lập trình R? Ma trận có thể được tạo bằng hàm ma trận (). Kích thước của ma trận có thể được xác định bằng cách truyền giá trị thích hợp cho các đối số NROW và NCOL. Cung cấp giá trị cho cả hai chiều là không cần thiết.using the matrix() function. Dimension of the matrix can be defined by passing appropriate value for arguments nrow and ncol . Providing value for both dimension is not necessary.