similar to: maintaining variable types in data frames

Displaying 20 results from an estimated 10000 matches similar to: "maintaining variable types in data frames"

2011 Feb 28
2
converting the string columns in a data.frame to factors?
Dear All, I'm not sure if I understand the parameter stringsAsFactors correctly. I'm trying to convert the string columns in aframe1 to factors. But it seems stringsAsFactors=T in as.data.frame() doesn't do anything. Could anybody let know what is the correct way to converting strings to factors? > aframe1=data.frame(x=LETTERS[1:10], y=LETTERS[1:10], stringsAsFactors=F) >
2017 Jul 07
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: > > This is not serious problem but I just wonder if someone can explain what is happening. > The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask.
2017 Jul 08
2
Factor vs character in a data.frame vs vector
Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: > On Jul 7, 2017, at 6:03
2017 Jul 08
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 7:03 PM, John Kane <jrkrideau at yahoo.ca> wrote: > > Thanks Marc. > It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame. I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. Welcome John. Going back to
2013 Aug 26
1
Loop for converting character columns to Numeric
Hi, Suppose you created a dataframe like this: set.seed(28) ?dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE) ?str(dat1) #'data.frame':??? 5 obs. of? 3 variables: # $ V1: chr? "a" "b" "c" "d" ... # $ V2: chr? "1" "2" "10" "18" ... # $ V3: chr?
2013 Feb 17
1
addition in the initial question
Dear Elisa, Try this: vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45) vec2<-vec1[1:26] names(vec2)<-LETTERS[1:26] label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i)
2009 May 07
1
paste with apply, spaces and NA
Hello everyone, I've come up with a problem with using paste() inside apply() that I can't seem to solve. Briefly, if I'm using paste to collapse the rows of a data frame, AND the data frame contains strings with spaces, AND there are NA values in subsequent columns, then paste() introduces spaces. This only happens with that particular combination of data values and commands. I have
2013 Jan 02
2
Read many cvs files
Hello R helpers, I would like to automate this code for many files of the same type. But I don´t know how to make it. In particular, i don´t know how to read many files each one as an r object with the name of the file. Then a for loop would be sufficient, right? Many thanks and a happy new year. Dominic datos <- read.table('global2001.csv',head=T,sep=';',stringsAsFactors=F)
2012 Sep 16
2
multi-column factor
I have a data frame with columns which draw on the same underlying universe, so I want them to be factors with the same level set: --8<---------------cut here---------------start------------->8--- > z <- data.frame(a=c("a","b","c"),b=c("b","c","d"),stringsAsFactors=FALSE) > str(z) 'data.frame': 3 obs. of 2
2013 Feb 19
1
data format
Hi, Try this: el<- read.csv("el.csv",header=TRUE,sep="\t",stringsAsFactors=FALSE) ?elsplit<- split(el,el$st) ? datetrial<-data.frame(date1=seq.Date(as.Date("1930.1.1",format="%Y.%m.%d"),as.Date("2010.12.31",format="%Y.%m.%d"),by="day")) elsplit1<- lapply(elsplit,function(x)
2012 Mar 14
3
Needing a better solution to a lookup problem.
I have a solution (actually a few) to this problem, but none are computationally efficient enough to be useful. I'm hoping someone can enlighten me to a better solution. I have data frame of chromosome/position pairs (along with other data for the location). For each pair I need to determine if it is with in a given data frame of ranges. I need to keep only the pairs that are within any of
2007 Oct 18
2
How to avoid conversion to factors (data frame to zoo)
Hi all, I was trying to convert a data frame to a zoo object so I can use some time series functions like lag(). But it seems then everything became a factor, so I have to convert it back to numeric to run the correct regressions. Is there a way to avoid it? Here is an example: ############################# a <- data.frame(nn =as.character(c("a", "b", "c",
2015 Oct 08
3
Tranformar falsas variables char en numéricas
Hola usuarios de R, Antes de nada presentarme, soy nuevo en R (antiguo... y bueno actual usuario de SAS), llevo menos de un mes y estoy intentando empezar con pequeñas cosas. Hay un tema que me está llevando bastante tiempo y por más que investigo y hago pruebas no logro saber como se hace; veréis tengo un data.frame el cuál tiene bastante variables y todas ellas clasificadas como char, sin
2013 Mar 29
1
Dataframe manipulation
Hi Adam, I hope this is what you wanted: dat1<- read.csv("example.csv",sep="\t",stringsAsFactors=FALSE) ?str(dat1) #'data.frame':??? 102 obs. of? 5 variables: # $ species? : chr? "B. barbastrellus" "E. nilssonii" "H. savii" "M. alcathoe" ... # $ period?? : chr? "dusk" "dusk" "dusk"
2011 May 15
2
Unexpected behaviour as.data.frame
I use the following code to create two data.frames d1 and d2 from a list: types <- c("integer", "character", "double") nlines <- 10 d1 <- as.data.frame(lapply(types, do.call, list(nlines)), stringsAsFactor=FALSE) l2 <- lapply(types, do.call, list(nlines)) d2 <- as.data.frame(l2, stringsAsFactors=FALSE) I would expect d1 and d2 to be the
2015 Oct 08
1
Tranformar falsas variables char en numéricas
Hola, Una manera muy sencilla de hacerlo es esta: #------------------------------- whatcol <- 0 for(i in 1:ncol(d)){ whatcol[i] <-class(d[,i]) } whatcol #-------------------------------- > whatcol <- 0 > for(i in 1:ncol(d)){ + whatcol[i] <-class(d[,i]) + } > whatcol [1] "character" "character" "factor" "factor"
2017 Jun 11
3
remove
Hi all, I have a date issue and would appreciate any help. I am reading a field data and n one of the columns I am expecting a date but has non date values such as character and empty. space. Here is a sample of my data. KL <- read.table(header=TRUE, text='ID date 711 Dead 712 Uknown 713 20-11-08 714 11-28-07 301 302 09-02-02 303 09-21-02',stringsAsFactors = FALSE, fill =T)
2018 Mar 05
0
Help with apply and new column?
Comments interspersed, and some code at the end. On Mon, 5 Mar 2018, Sariya, Sanjeev wrote: > Thanks. I think nabble is good for programming questions. Bear with me > if I'm incorrect. You may have found R-help archives at Nabble, but R-help has nothing to do with Nabble. > > Data: Genomics SNP information I know almost nothing about using R for genomics. > Goal: I need
2011 Dec 08
2
read.table question
Hello All, This works, results <- read.table("plink.txt",T) while this doesn't. results <- read.table("plink.txt") Make sure your data frame contains columns CHR, BP, and P What does adding the "T" in read.table do? Which argument does this correspond to? I tried searching for it but didn't find the answer in: read.table(file, header = FALSE,
2017 Jul 07
2
Factor vs character in a data.frame vs vector
This is not? serious problem but I just wonder if someone can explain what is happening. The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. Thanks #================================================ dat1 <- data.frame(aa = letters[1:10]) str(dat1)