Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Producing a new dataframe from an old dataframe?

Tags:

dataframe

r

I want to produce a new dataframe from an old big one (many variables) I use the cbind.data.frame function and it goes like this

new <- cbind.data.frame(old$var1, old$var2, old$var3)
str(new)
  'data.frame': 100 obs. of  3 variables:
$ old$var1        : num

Why does the var1 still belong to old$ ?
I wanted to use just new$var1 but it returns object not found.

What am I doing wrong?

like image 382
Pulse Avatar asked Jul 13 '13 02:07

Pulse


People also ask

How do I create a new DataFrame from an existing DataFrame in PySpark?

To create a PySpark DataFrame from an existing RDD, we will first create an RDD using the . parallelize() method and then convert it into a PySpark DataFrame using the . createDatFrame() method of SparkSession.

How do I create a DataFrame from an old DataFrame in R?

To convert an old data frame to a new data frame, we can simply set the new name. For example, if we have a data frame called df and want to convert it to a new one let's say df_new then it can be done as df_new<-df. But if we want to change the column names as well then data.

How do I convert a DataFrame from two data frames?

Another way to combine DataFrames is to use columns in each dataset that contain common values (a common unique id). Combining DataFrames using a common field is called “joining”. The columns containing the common values are called “join key(s)”.


1 Answers

Combine both of the other other answers by doing this:

New <- data.frame("var1" = old$var1, 
                  "var2" = old$var2, 
                  "var3" = old$var3) 
like image 96
Andy Clifton Avatar answered Nov 15 '22 23:11

Andy Clifton