Try this:
sweep(as.matrix(df), 2, as.matrix(df[1,]))
On Tue, Jan 25, 2011 at 7:20 AM, Vincy Pyne wrote:
> Dear R helpers
>
> I have a dataframe as
>
> df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
>
> > df
>x y
> 1 1 102
> 2 14 500
> 3 3 40
> 4 21 101
> 5 11 1
On 2011-01-25 01:20, Vincy Pyne wrote:
Dear R helpers
I have a dataframe as
df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
df
x y
1 1 102
2 14 500
3 3 40
4 21 101
5 11 189
# Actually I am having dataframe having multiple columns. I am just giving an
exampl
I always forget about sapply():
df_new <- sapply(df, FUN=function(x) x-x[1])
Ivan
Le 1/25/2011 10:33, Ivan Calandra a écrit :
Hi,
Try this:
df_new <- as.data.frame(lapply(df, FUN=function(x) x-x[1]))
I hope it works!
Ivan
Le 1/25/2011 10:20, Vincy Pyne a écrit :
Dear R helpers
I have a dat
Hi,
Try this:
df_new <- as.data.frame(lapply(df, FUN=function(x) x-x[1]))
I hope it works!
Ivan
Le 1/25/2011 10:20, Vincy Pyne a écrit :
Dear R helpers
I have a dataframe as
df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
df
x y
1 1 102
2 14 500
3 3 40
4 2
Hi:
> df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
> apply(df, 2, function(x) x - x[1])
x y
[1,] 0 0
[2,] 13 398
[3,] 2 -62
[4,] 20 -1
[5,] 10 87
HTH,
Dennis
On Tue, Jan 25, 2011 at 1:20 AM, Vincy Pyne wrote:
> Dear R helpers
>
> I have a dataframe as
>
Dear R helpers
I have a dataframe as
df = data.frame(x = c(1, 14, 3, 21, 11), y = c(102, 500, 40, 101, 189))
> df
x y
1 1 102
2 14 500
3 3 40
4 21 101
5 11 189
# Actually I am having dataframe having multiple columns. I am just giving an
example.
I need to subtract all the rows of df
6 matches
Mail list logo