Questions tagged [r-colnames]
114 questions
3
votes
1 answer
create a new data frame with columns from another data frame based on column names in R
Data frame A exists.
I want to create Data frame B and insert certain columns from data frame A in Data frame B.
I do not want to use the column numbers but the column names to do that
Thank you very much!!!!

Yaron Nolan
- 153
- 1
- 1
- 8
3
votes
0 answers
Putting greek letters in column names
Is there any way to include Greek letters (α,β,γ) into column names of a matrix? I know you use:
colnames()<-c("column 1","column 2","column 3".....)
to add column names but when i tried to paste in the letters...
colnames(mymatrix)<-c("random…

Summer Gleek
- 334
- 5
- 15
3
votes
2 answers
keep column names when applying as.vector to a matrix slice
Let us say I have a matrix,
A = matrix(c(1,23,4,5,6,3,2,2,1,2), nrow = 2, ncol = 5)
with rownames and column names given by,
rownames(A) = c('row1', 'row2')
colnames(A) = c('es', 'one', 'column', 'no', '5')
If I do:
> my.slice = A[1,,drop=FALSE]
…

Dnaiel
- 7,622
- 23
- 67
- 126
2
votes
2 answers
Renaming columns if a specific character string doesn't exist
I'm looking to rename colnames to include the characters _16S_sed if they're not present. For example I have the dataset
> dput(dataframe1)
structure(list(GL11_DN_1_16S_sed = structure(1:3, .Label = c("val1",
"val2", "val3"), class = "factor"),…

Geomicro
- 303
- 3
- 13
2
votes
1 answer
R user function column name selection with or without quotes
I want to be able to enter a column name of a tibble in a user function with or without using quotation marks. Using myfunc function below I can enter the column name, but I can't encapsulate it within "". Is there a way to use both methods in a…

Andrew
- 111
- 4
2
votes
1 answer
Is there a way to name column names or rownames?
, , RE
Midterm Final mean
A 81.9 75.1 78.5
B 78.3 69.2 73.8
C 79.6 74.4 77.0
mean 79.9 72.9 76.4
I'm trying to name the rows and columns so that "Subject" is above the rows "A,B,C, and mean", and "Exam" is above the…

redwoods
- 59
- 5
2
votes
1 answer
Correlate vectors whose colnames match the values of two variables in each row in r dataframe
I have this dataframe in r (link) (Example rows and columns below)
FocalID Mother Adelaide Asimov Austen Brazzaville Lusaka Kinshasa
Adelaide HalfEar 0 0.0380 0.0417 0.0366 0.0278 0.0385
Asimov Lusaka 0.0380 0 …

Vittoria Roatti
- 63
- 7
2
votes
2 answers
I want to change the columns names with a loop
i have a datasets column names looking like that
state.abb, state.area, state.division, state.region
i want to change the names of the columns and delete the "state." part to leave only "abb", "area","division", and "region".
i wrote this code using…

Houssam Baiz
- 43
- 6
2
votes
1 answer
Return list of columns containing data outside a predetermined range in r
In order to filter a data.frame for only the the columns of interest I need to find the columns in this data.frame containing data outside a specific range.
Let the data.frame…

Juan
- 171
- 1
- 12
2
votes
1 answer
Weird multiple columns in one column in R (fromJSON)
library(jsonlite)
test <-as.dataframe(fromJSON('http://api.worldbank.org/v2/countries/all/indicators/SH.STA.ACSN?format=json')[2])
names(test)
However, it looks like there are more columns, such as the "country" column actually has "country.value"…

Jingyu Gao
- 71
- 3
2
votes
0 answers
R naming convention/tricks for many columns in data.table / data.frame
I have a list of, say, n=10 data.tables (or data.frames).
Performing names(myList) returns the unique table names.
Performing names(myList[[i]]) (for i in 1:n) returns identical output for each value of i - i.e. each data.table has identical column…

n1k31t4
- 2,745
- 2
- 24
- 38
2
votes
1 answer
R How to remove characters from long column names in a data frame
I have a large dataframe with long column names in it. I would like to shorten the columnnames by dropping characters before a colon sign (:), the sign is present in every column name in the dataframe columns.
Looking for a way to perform this on a…

jonas
- 13,559
- 22
- 57
- 75
2
votes
3 answers
Split characters in column names to new columns with logical values in rows
I am trying to split column name strings into separate columns but the issue I am facing is that the rows have logical values. There are a few posts that split columns with strings in the rows but I could not find any posts with logical values.
My…

Rkook
- 63
- 1
- 11
1
vote
1 answer
Simple way to set R column names as index
I'm new to R and looking for an easy way to get rid of column names in a R dataframe and return the names to their index [1,2,3,4..]. Something like combining .iloc and reset_index in pandas. I need the colnames initially before returning them to…

Maya
- 13
- 3
1
vote
2 answers
Compare the column names of multiple CSV files in R
I'm combining 12 CSV files into one dataframe in R. Before doing this I want to ensure all the column names are an exact match with each other. I've made a dataframe where each column is the column names of the 12 CSV files.
jul21_cols <-…

Michael Thompson
- 13
- 4