Displaying 20 results from an estimated 10000 matches similar to: "converting the string columns in a data.frame to factors?"
2010 Feb 03
3
How to flatten a tree (based on list) to a certain depth?
Suppose that I have the following list of lists of frames 'root'
(let's call it a 'tree' of frames). I want to flatten it to be a list
of frames. However, if I unlist(root), it will flatten the frames as
well. Is there a simply way to flatten the tree to certain depth?
aframe1=data.frame(x=1:3,y=1:3)
aframe2=data.frame(u=7:9,v=11:13)
aframe3=data.frame(p=3:5,q=6:8)
2010 Sep 06
2
dataframe row names from list
Hi,
I have a list which looks like this...
> str(y)
List of 10
$ : chr [1:4] "ABCD" "5" "0" "1"
$ : chr [1:4] "DEF" "15" "1" "16"
$ : chr [1:4] "AAA" "2" "17" "8"
$ : chr [1:4] "SSS" "15" "25" "1"
$ : chr [1:4] "III"
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?
2009 Jan 22
1
maintaining variable types in data frames
Suppose X and Y are two data frames with the same structures, variable
names and dimensions but with different data and different patterns of
missing. I want to replace missing values in Y with corresponding values
from X. I'll construct a simple two-by-two case:
> X <- as.data.frame(matrix(c("a","b",1,2),2,2), stringsAsFactors=FALSE)
> X[,2] <-
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
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
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.
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)
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
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,
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",
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
2010 Feb 10
2
replace a for loop
Hi everybody!
I'm still quite new in R and I don't really understand this whole
"vectorization" thing.
For now, I use a for loop (and it works fine), but I think it would be
useful to replace it.
I want to export the result of a test statistic, which is stored as a
list, into a csv file. I therefore have to export each element of the
list separately.
Here is the code:
----
2017 Aug 25
1
splitting a dataframe in R based on multiple gene names in a specific column
If row numbers can be dispensed with, then tidyr makes this easy with
the unnest function:
#####
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(purrr)
2016 May 12
2
Division entre el numero de ocurrencias parciales y totales dentro de un DataFrame de manera eficiente
Hola:
A ver si me podéis ayudar que estoy atascado...
Necesito contar los subcasos de la columna 2 de un dataframe respecto a los
casos de la columna 1.
Es decir, tengo un data.frame
a<-c(rep(c('a','b','c','b','c'),3),'b')
b<-c(rep(c('x','y','z','w'),4))
c<-c(rep(c(1,1,0,0),4))
2011 Jan 18
2
dataframe: string operations on columns
Dear all,
how can I perform a string operation like strsplit(x," ") on a column
of a dataframe, and put the first or the second item of the split into a
new dataframe column?
(so that on each row it is consistent)
Thanks
Boris
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)
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
2011 Feb 25
4
Error
Hi, I am running the following script for a different (much larger data
frame):
DF = data.frame(read.table(textConnection(" A B C D E
1 1 a 1999 1 0
2 1 b 1999 0 1
3 1 c 1999 0 1
4 1 d 1999 1 0
5 2 c 2001 1 0
6 2 d 2001 0 1
7 3 a 2004 0 1
8 3 b 2004 0 1
9 3 d 2004 0 1
10 4 b 2001 1 0
11 4 c 2001 1 0
12 4 d 2001 0