rowname

R returning partial matching of row names

独自空忆成欢 提交于 2021-02-18 22:37:29
问题 I've run into the following issue vec <- c("a11","b21","c31") df <- data.frame(a = c(0,0,0), b = c(1,1,1), row.names = vec) df["a",] returns df["a",] a b a11 0 1 However, "a" %in% vec and "a" %in% rownames(df) both return False R is allowing for partial matching of the string when using letter followed by numbers for row names. I have replicated this on R v3.2.2 and R v3.2.1. Even df[["a",1,exact=T]] returns 0 Is there anything I can set such that R does not allow this partial matching? 回答1:

Changing dimnames of matrices and data frames in R

梦想的初衷 提交于 2021-02-04 15:41:29
问题 Let's say I have created the following matrix: > x <- matrix(1:20000,nrow=100) > x[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 101 201 301 401 501 601 701 801 901 [2,] 2 102 202 302 402 502 602 702 802 902 [3,] 3 103 203 303 403 503 603 703 803 903 [4,] 4 104 204 304 404 504 604 704 804 904 [5,] 5 105 205 305 405 505 605 705 805 905 [6,] 6 106 206 306 406 506 606 706 806 906 [7,] 7 107 207 307 407 507 607 707 807 907 [8,] 8 108 208 308 408 508 608 708 808 908 [9,] 9

Changing dimnames of matrices and data frames in R

坚强是说给别人听的谎言 提交于 2021-02-04 15:41:06
问题 Let's say I have created the following matrix: > x <- matrix(1:20000,nrow=100) > x[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 101 201 301 401 501 601 701 801 901 [2,] 2 102 202 302 402 502 602 702 802 902 [3,] 3 103 203 303 403 503 603 703 803 903 [4,] 4 104 204 304 404 504 604 704 804 904 [5,] 5 105 205 305 405 505 605 705 805 905 [6,] 6 106 206 306 406 506 606 706 806 906 [7,] 7 107 207 307 407 507 607 707 807 907 [8,] 8 108 208 308 408 508 608 708 808 908 [9,] 9

Merge data frames based on numeric rownames within a chosen threshold and keeping unmatched rows as well

只谈情不闲聊 提交于 2020-01-15 10:43:36
问题 How can I merge two data frames based on their numeric rownames while setting a threshold for the match? df1 <- structure(list(c(4974622.505928, 170582.149747, 130545.004516, 143528.819582, 49416.594892, 51879.515558, 52027.462651, 42491.317116, 49173.145029, 44040.01261), c(4664319.00309, 266278.599338, 204772.412837, 204819.210688, 77718.961761, 82742.852809, 79706.774944, 67123.603629, 67264.401059, 66750.260768), c(5906075.502923, 385318.121061, 296824.944672, 308432.753482, 113407.50333,

How do I extract rownames from a matrix?

时间秒杀一切 提交于 2020-01-02 01:21:10
问题 I have a matrix with rownames that are dates. I want to extract these row names into a variable, and then use rownames() to apply these dates to another matrix I have. Let's say the matrix is called 'data.matrix'. Whenever I run: data.matrix[,0] I get a printout of all the dates. So I do this: v <- data.matrix[,0] When I return v I get a nice list of all the dates. But when I use: rownames(other.matrix) <- v And then I return: head(other.matrix) I don't get any new column names. Also, when I

How to get row index number for particular name(s)?

前提是你 提交于 2019-12-21 17:50:08
问题 How can one determine the row index-numbers corresponding to particular row names? I have a vector of row names, and I would like to use these to obtain a vector of the corresponding row indices in a matrix. I tried row() and as.integer(rownames(matrix.object)) , but neither seems to work. 回答1: In addition to which , you can look at match : m <- matrix(1:25, ncol = 5, dimnames = list(letters[1:5], LETTERS[1:5])) vec <- c("e", "a", "c") match(vec, rownames(m)) # [1] 5 1 3 回答2: Try which :

Find row name in R

微笑、不失礼 提交于 2019-12-20 07:51:13
问题 I wonder how I can extract row name from row number? x <- data.frame( A = 1:10, B = 21:30 ) rownames( x ) <- sample( LETTERS, 10 ) > x A B J 1 21 A 2 22 I 3 23 G 4 24 H 5 25 B 6 26 P 7 27 Z 8 28 O 9 29 R 10 30 > x[ "H",] A B H 5 25 I want to find what is the row name of specific row? for example row name of row=3 also which rowname contains the value 30? thanks 回答1: set.seed(42) x <- data.frame( A = 1:10, B = 21:30 ) rownames( x ) <- sample( LETTERS, 10 ) x ## A B ## X 1 21 ## Z 2 22 ## G 3

How to remove the rownames from the file

随声附和 提交于 2019-12-19 11:27:42
问题 I have a file which looks like this.. "Locations" "X9442" "X5997" "1" "cg00000957" 0.87 0.86 "2" "cg00001349" 0.78 0.78 "3" "cg00001583" 0.06 0.08 "4" "cg00002028" 0.01 0.01 I wish to remove the row names and make it look like as follows: "Locations" "X9442" "X5997" "cg00000957" 0.87 0.86 "cg00001349" 0.78 0.78 "cg00001583" 0.06 0.08 "cg00002028" 0.01 0.01 I tried various things, but I am not able to remove those indexes while doing write.table. Also sometimes the header "Locations" shifts

Why do identical dataframes become different when changing rownames to the same

天大地大妈咪最大 提交于 2019-12-19 09:44:07
问题 I've come across a strange behavior when playing with some dataframes: when I create two identical dataframes a,b , then swap their rownames around, they don't come out as identical: rm(list=ls()) a <- data.frame(a=c(1,2,3),b=c(2,3,4)) b <- a identical(a,b) #TRUE identical(rownames(a),rownames(b)) #TRUE rownames(b) <- rownames(a) identical(a,b) #FALSE Can anyone reproduce/explain why? 回答1: This is admittedly a bit confusing. Starting with ?data.frame we see that: If row.names was supplied as

Removing display of row names from data frame

拥有回忆 提交于 2019-12-17 05:00:45
问题 I am creating a dataframe using this code: df <- data.frame(dbGetQuery(con, paste('select * from test'))) Which results in this: UID BuildingCode AccessTime 1 123456 BUILD-1 2014-06-16 07:00:00 2 364952 BUILD-2 2014-06-15 08:00:00 3 95865 BUILD-1 2014-06-06 09:50:00 I am then trying to remove the row names (1, 2, 3, etc) as suggested here by using this code: rownames(df) <- NULL But then when I print out df it still displays the row names. Is there a way to not include the row names when