Skip to main content

All Questions

Tagged with
-1 votes
2 answers
76 views

Identify which of two vectors is numeric and which is strings in R (but more generally for other platforms as well)

I need to write a function that identifies which of two vectors it receives is (the most likely to be) the numeric vector and which is (most likely to be) the character vector. The two vectors might ...
Leonhard Euler's user avatar
2 votes
4 answers
593 views

How to change character to numeric vector in R

Given a, I have to return b: a <- "[1, 2, 3]" # class: character b <- c(1, 2, 3) # class: numeric I have tried strsplit() and paste() functions but both are not working well. ...
Richard's user avatar
  • 507
2 votes
1 answer
69 views

A function for referring to columns by either name or index

I would like to be able to refer to columns by name and index in one vector. As example I specify only: EDIT: I changed the order of the original vector as I want the order to not matter. columns &...
Tom's user avatar
  • 2,351
0 votes
1 answer
141 views

R converts to numeric when sorting (arrange)

How can I stop R from converting strings to numeric while sorting a character vector of numbers? example using dplyr arrange(): nomenclature <- read_csv2(file('~/nomenclature.txt', encoding="UTF-8"...
guzu92's user avatar
  • 737
-1 votes
3 answers
4k views

Extract numeric elements from a vector

I have a vector 'a' which has numeric and non-numeric elements. I want to extract the numeric elements from the vector and build a new vector. How do I do this? So if a is: a = c(15, 3, 44, "hello", ...
Sinha's user avatar
  • 456
2 votes
1 answer
747 views

Convert a column of strings in data frame into numeric in R (not the usual kind)

So in R I have a column consisting of strings that look like something similar to this: "Peter","Paul","John","Melissa","Paul","Peter" ... And I want to convert these names to a numerical ID format, ...
hippie_poe's user avatar