jim holtman wrote:
> You have to return a value from the function in the lapply and assign the
> result to another object:
>
>
>> df <- data.frame(a=1,b=2,c=3,d=4)
>> a <- list(df,df,df,df)
>> # to change the name of the second, you have to change the name and then
>>
> return
>
>> # the
Hi:Â you have to return the dataframe inside the lapply. I also changed =
to <- but I doubt that matters.
d1 <- data.frame(x1=1,x3=4)
d2 <- data.frame(x1=2,x3=5)
d3 <- data.frame(x1=3,x3=6)
d4 <- data.frame(x1=4,x3=7)
a = list(d1,d2,d3,d4)
print(a)
lapply(a,function(.df
You have to return a value from the function in the lapply and assign the
result to another object:
> df <- data.frame(a=1,b=2,c=3,d=4)
> a <- list(df,df,df,df)
> # to change the name of the second, you have to change the name and then
return
> # the dataframe as the return value and assign it bac
Hi,
Say I have dataframes d1, d2, ... , dn, and I want to apply a
function to all of them. For example, say I want to change the name
of the second variable in each dataframe to "x2". The following doesn't work:
a = list(d1,d2,d3,d4)
lapply(a,function(x) names(x)[2] = "x2")
What would work
4 matches
Mail list logo