Well, my solution with the loop might be slower (even though I don't see
any difference with my system, at least with up to 100 lines and 3
strings to separate), but it works whatever the number of strings.
But I should have renamed the columns outside of the loop:
names(df)[2:3] <- paste("a", 1
On 01/18/2011 07:05 PM, Henrique Dallazuanna wrote:
> Or:
>
> read.table(textConnection(as.matrix(df)), sep = " ")
no, that's too simple: you can't use regular expressions. (well, i
guess it's enough for the original problem.)
vQ
>
>
> On Tue, Jan 18, 2011 at 11:02 PM, Waclaw Kusnierczyk
Or:
read.table(textConnection(as.matrix(df)), sep = " ")
On Tue, Jan 18, 2011 at 11:02 PM, Waclaw Kusnierczyk wrote:
> Assuming every row is split into exactly two values by whatever string you
> choose as split, one fancy exercise in R data structures is
>
>dfsplit = function(df, split)
>
Assuming every row is split into exactly two values by whatever string
you choose as split, one fancy exercise in R data structures is
dfsplit = function(df, split)
as.data.frame(
t(
structure(dim=c(2, nrow(df)),
unlist(
On 2011-01-18 08:14, Ivan Calandra wrote:
Hi,
I guess it's not the nicest way to do it, but it should work for you:
#create some sample data
df<- data.frame(a=c("A B", "C D", "A C", "A D", "B D"),
stringsAsFactors=FALSE)
#split the column by space
df_split<- strsplit(df$a, split=" ")
#place th
On 2011-01-18 08:14, Ivan Calandra wrote:
Hi,
I guess it's not the nicest way to do it, but it should work for you:
#create some sample data
df<- data.frame(a=c("A B", "C D", "A C", "A D", "B D"),
stringsAsFactors=FALSE)
#split the column by space
df_split<- strsplit(df$a, split=" ")
#place th
> 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)
Have a look at str_split_fixed in the stringr package.
Hadley
--
Assistant Profes
Hi,
I guess it's not the nicest way to do it, but it should work for you:
#create some sample data
df <- data.frame(a=c("A B", "C D", "A C", "A D", "B D"),
stringsAsFactors=FALSE)
#split the column by space
df_split <- strsplit(df$a, split=" ")
#place the first element into column a1 and the
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
__
R-help@r-project.
9 matches
Mail list logo