Questions tagged [r-colnames]

114 questions
53
votes
4 answers

Row names & column names in R

Do the following function pairs generate exactly the same results? Pair 1) names() & colnames() Pair 2) rownames() & row.names()
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
13
votes
4 answers

Using variable value as column name in data.frame or cbind

Is there a way in R to have a variable evaluated as a column name when creating a data frame (or in similar situations like using cbind)? For example a <- "mycol"; d <- data.frame(a=1:10) this creates a data frame with one column named a rather…
JasonMond
  • 1,440
  • 1
  • 16
  • 30
11
votes
1 answer

R extract data frame from list without prefixes in column names

I place a data frame inside the list. Then when try to extract it back - I get all column names prefixed with list key for this data frame, is there a way to extract data frame exactly as it was passed initially? cols<-c("column1", "Column2",…
Volder
  • 972
  • 4
  • 13
  • 29
7
votes
5 answers

Change column names in dataframe based on matching to another dataframe by dplyr

I have a dataframe where I want to change the column names by matching to another dataframe. Example dataframe with data and column names: df <- data.frame("Gene_Symbol" = c("Gene1","Gene2","Gene3","Gene4","Gene5","Gene6","Gene7"), …
Henrik
  • 105
  • 3
7
votes
3 answers

How can I Change dimnames of matrices and data frames in R

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 …
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
6
votes
3 answers

appending or Pasting names to Column names in R

I Have a tab delim file with 400 columns.Now I want to append text to the column names.ie if there is column name is A and B,I want it to change A to A.ovca and B to B.ctrls.Like wise I want to add the texts(ovca and ctrls) to 400 coulmns.Some…
Dinesh
  • 643
  • 5
  • 16
  • 31
6
votes
2 answers

sapply - retain column names

I am trying to summarise the mean, sd etc for a number of different columns (variables) in my dataset. I have coded my own summarise function to return exactly what I need and am using sapply to apply this function to all the variables at once. It…
5
votes
1 answer

Why doesn't R throw an error when I use only the initial part of my column name in a data frame?

I have a data frame containing various columns along with sender_bank_flag. I ran the below two queries on my data frame. sum(s_50k_sample$sender_bank_flag, na.rm=TRUE) sum(s_50k_sample$sender_bank, na.rm=TRUE) I got the same output from both the…
Harsh Khad
  • 99
  • 1
  • 7
5
votes
2 answers

How can I write a table function to coerce the order of column names in the output of table()?

I would like to change the column order output from the table function in R. I can only find information about manipulating column order for data.table (not what I want). The order of the columns ("No" and "Yes") has always been the consistent when…
B.Kenobi
  • 209
  • 3
  • 6
5
votes
1 answer

How can I assign a variable's value to column name in plyr?

Is there any way to assign a variable's value to the resultant column name in plyr? So in this code: column_name <- 'total' df <- data.frame(a=c('a','b'), b=c(1,2)) ddply(df, .(a), summarise, column_name=sum(b)) As you know, this spits out a data…
Blaszard
  • 30,954
  • 51
  • 153
  • 233
4
votes
3 answers

How can I compare column names of two separate data frames in R?

I have 2 data frames in R with epigenetic data. To use one of them as a train set and the other as a test set in the glmnet package, the column number if them have to match. As both of the data frames contain more than 800000 columns, I'm looking…
ACZ
  • 91
  • 1
  • 5
4
votes
2 answers

How can I make R print printed column names vertically?

I believe in meaningful variable names. Unfortunately this often means that there are huge white gaps when I look at a data.frame in the R console: Is there a way to tell R to print the column names vertically, like this: It doesn't need to be in…
user1322720
4
votes
3 answers

How can I reorder columns in a 'canonical' way after mutate_each or summarise_each?

Take the following example. library(dplyr) temp <- data.frame(lapply(1:3, function(i) rnorm(5, 0, 1))) names(temp) <- paste0("X", 1:3) temp_each <- temp %>% mutate_each(funs(mean, median)) Examining the names of temp_each, we see that >…
Alex
  • 15,186
  • 15
  • 73
  • 127
4
votes
3 answers

Set a dataframe as column names for another data frame

So I have a data frame (called SNPlist) which is of dimensions 1 by 500000 (rows by columns). I want SNP list to be the column names for my dataframe of data (called Data) which is of dimension 100 by 500000. I already tried colnames(Data) <-…
user2603386
3
votes
2 answers

Reorder matrix columns based on colnames suffix and the order of a character vector

I have a matrix that looks like this cols <- c("foo_AFG", "baz_SYR", "baz_TUR", "foo_SYR", "foo_TUR", "baz_AFG") foo <- matrix(ncol = length(cols)) colnames(foo) <- cols w <- c("SYR", "AFG", "TUR") foo foo_AFG baz_SYR baz_TUR foo_SYR foo_TUR…
umbe1987
  • 2,894
  • 6
  • 35
  • 63
1
2 3 4 5 6 7 8