Questions tagged [r-colnames]

114 questions
0
votes
1 answer

merge data.frame with multidimensional list

I have a data frame 'QARef" whith 25 variables. There are only 5 unique jobs (3rd column) but lots of rows per job: str(QARef) 'data.frame': 648 obs. of 25 variables: I'm using tapply to generate mean values across all 5 jobs for certain…
MarkH
  • 122
  • 9
0
votes
1 answer

Accessing column by name in data.frame: return NA if column doesn't exists

Is there a more efficient way to check column existence by it's name, returning column if it exists or return na if it doesn't exists? Now i'm using following function: TryGetColumn <- function(x, column.name, column.names, value.if.not.exists) { …
Eldar Agalarov
  • 4,849
  • 4
  • 30
  • 38
0
votes
2 answers

R dataframe define column names at creation

I get monthly price value for the two assets below from Yahoo: if(!require("tseries") | !require(its) ) { install.packages(c("tseries", 'its')); require("tseries"); require(its) } startDate <- as.Date("2000-01-01", format="%Y-%m-%d") MSFT.prices =…
Zhubarb
  • 11,432
  • 18
  • 75
  • 114
0
votes
1 answer

R colnames() assigning every element in list to first column

I am trying to rename the 104 columns in a dataframe (df) using a list or character vector (I've tried it both ways). Instead of assigning the 104 elements in the vector or list to the 104 columns one each, it assigns all 104 elements to the first…
user2547308
  • 143
  • 2
  • 8
-1
votes
1 answer

How to use values of a column in defining bounds of another column values in R?

While processing my data (txt files), I need to define a lower and upper bound for my data in a way that values in between the bounds should remain as they are, else should become NA. I am using following code in R: if ("K" %in% colnames(x)) { …
-1
votes
1 answer

Renaming Columns with index with a For Loop in R

I am writing this post to ask for some advice for looping code to rename columns by index. I have a data set that has scale item columns positioned next to each other. Unfortunately, they are oddly named. I want to re-name each column in this…
JFC_Mx
  • 23
  • 5
-1
votes
4 answers

Add a suffix and prefix to some column names in R

I have a column name Food_Q_74 in a loop that becomes Food_Q_75 Food_Q_76 etc I need to make it look like Q_74_A1, Q_75_A1 etc I need to delete Food_ at the beginning and add _A1 at the end. So I am NOT adding a prefix as suggested. I am not only…
-1
votes
1 answer

use name_repair for mids object in mice

I have a set of 5 datasets that were generated through multiple imputation using the mice package. I'm running a hierarchical regression on these datasets, but when I try to pool the results, I get an error that "Column 6 must be named" and to use…
J.Sabree
  • 2,280
  • 19
  • 48
-2
votes
1 answer

How can I make column names like "X_re" after recoding?

I recoded columns 'satface1, satface2,..., satface6' and I want to make new columns in my data name 'satface1_re, satface_2, ..., satface6_re'. How can I make it? What I tried was: data$re <- data %>% select((num_range("satface",1:6,width = 1)))…
Yubin
  • 7
  • 1
1 2 3 4 5 6 7
8