Questions tagged [r-colnames]

114 questions
1
vote
2 answers

Getting dataframe column names with apply for graph title in R

I run the apply function on a dataframe's columns and perform several operations including plotting some graphs. I want to get the column names to use them as title of each graph. I found a post that uses lapply but I don't think I can use it since…
Bertrand G
  • 37
  • 6
1
vote
0 answers

column name of predict outcome cannot be specified in dataframe

I have a variable yhat which is the output of predict function, and assign it to a dataframe: x=matrix(rnorm(100*20),100,20) y=rnorm(100) cv.fit = cv.glmnet(x, y) x=matrix(rnorm(100*20),100,20) yhat = predict(cv.fit, s=cv.fit$lambda.1se, newx=x,…
Xin Niu
  • 533
  • 1
  • 5
  • 15
1
vote
2 answers

Getting a list of column names in ascending order for each row in a data frame

I have a data frame which consists of a column of IDs and many columns with different values for each ID, many of which are NA. e.g: ID w x y z 1 User1 3 2 NA NA 2 User2 7 9 NA 4 3 User3 NA NA 1 NA 4 User4 3 NA NA 5 Is there a way…
CeruLinh
  • 11
  • 2
1
vote
3 answers

How to get column name and column index

Hi I have the below dataframe. Since the column contains NA's the datatype of the column is character. Now, I need to get the column name and index which only contains String value. In the example below, I want to get the column name and column…
Anagha
  • 3,073
  • 8
  • 25
  • 43
1
vote
1 answer

name columns of dynamically chosen data.frame

I am trying to name the columns of a data frame, but the data frame is chosen dynamically. Any idea why this does not work? Below is an example, but in my real case, I get a different error. As of now, I would just like to know what causes either…
user3385769
  • 161
  • 6
  • 16
1
vote
1 answer

Unable to set column names to a subset of a dataframe

I run the following code, p is the dataframe loaded. a <- sort(table(p$Title)) a1 <- as.data.frame(a) tail(a1, 7) a Maths 732 Science 737 Physics 737 Chemistry 776 Social Science …
RpB
  • 305
  • 8
  • 18
1
vote
3 answers

Decision based on the headers of a data frame

I have a list of data frames : df [[1]] ID SignalIntensity SNR 1 109 6.182309 0.8453577 2 110 10.172777 4.3837078 3 111 7.292275 1.0725751 4 112 8.898467 2.3192185 5 113 9.591034 3.7133402 7 116 …
Agaz Wani
  • 5,514
  • 8
  • 42
  • 62
1
vote
2 answers

R: Index data frame columns by ranges of their names

I have a large number of huge data frames. Often in these data frames I have groups of columns with similar names that appear sequentially. The following is a simplified version of such data frame: > tmp <- data.frame(ID = 1:25, Item1 = sample(x…
panman
  • 1,179
  • 1
  • 13
  • 33
1
vote
2 answers

data.frame from lists in list, weird column names

I'm trying to make a data.frame from a "list in list" l <- list(c("sam1", "GSM6683", "GSM6684", "GSM6687", "GSM6688"), c("sam2", "GSM6681", "GSM6682", "GSM6685", "GSM6686")) df <- data.frame(l) 1) I get a date.frame with weird column names, how…
charisz
  • 302
  • 4
  • 12
0
votes
0 answers

how do i see all the column names in my dataset using colnames function without getting an error message?

The challenge i am facing here is that the name i used to save my dataframe cannot be found in the environment thereby making it difficult to see the column names of my dataset. this is the code am trying to…
0
votes
1 answer

Error of "incorrect number of dimensions" occurred when using lapply to a list of dataframes

I was dealing with a list of two dataframes. Both look this way. What I would like to do was to change the row names and column names so that they may look this way. Here is the code I used. # Create a list to hold both dataframes list_info <-…
0
votes
0 answers

Selecting specific matrix columns based on another matrix

I have a matrix with 10 columns named "PC1", "PC2" and so forth and another matrix containing certain columns names of the first matrix, which I'm supposed to extract. First matrix containing my data: set.seed(1234) A <-…
Nedralixx
  • 1
  • 1
0
votes
1 answer

Is it possible for column names to be hyperlinks in R function gt?

Using the function gt in R, I can get hyperlinks working for cells in the table, but I can't quite figure out how to do it for column names. library(gt) library(tidyverse) make_into_links <- function(vec){ clean_vec <- str_replace_all(vec[-1],…
0
votes
1 answer

How to remove all the columns for each row where Col X > 200?

I have data with various columns for say A, B, C, Cq, D, Dq, F, Fq, M, Mq, ..., X. I want that whenever column X has value > 200, that particular row for all the columns should be removed. My code in R is as below. Could anyone please help me in…
0
votes
0 answers

Conditional statement in R - col C should have valid values only when col A and B have valid values

I have data with various columns and I need to use few conditional statements on the columns. I am able to write following code successfully for conditions to be applied on two columns i.e., AB and MN. if ("ABq" %in% colnames(x)) { x[ABq != 0, AB…